﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Net.Mail;
using System.Threading.Tasks;
using System.Web.Mvc;
using static CIS.Web.Common.ConstValues;

namespace CIS.Web.Controllers
{
	[AllowAnonymous]
	[RoutePrefix("Mobile")]
	public class MobileController : BaseDbController
	{
		/// <summary>
		/// 报道单
		/// cheng
		/// </summary>
		public async Task<ActionResult> Index(string id)
		{
			var model = new ConferenceLocaleModel();

			var personal = await DbContext.ConferenceAttendenceInfo.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);
			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == personal.ConferenceId);

			var isBenefit = false;
			if (DateTime.Now >= conferenceMaster.BenefitStartDate && DateTime.Now <= conferenceMaster.BenefitEndDate)
			{
				isBenefit = true;
			}
			var payTypeId = DbContext.ConferencePaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.PaymentTypeId)?.PayId;

			//查询论文编号
			var essayList = await DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => personal.EssayId.Contains(x.ID.ToString()) &&
						x.EssayTitle != ConstValues.ChairmanReportCn &&
						x.EssayTitle != ConstValues.ChairmanReportEn)
					.ToListAsync();
			List<string> strList = new List<string>();
			essayList.ForEach(x =>
			{
				var reportType = DbContext.ReportMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.ReportId)?.ReportType;
				var rid = x.ID;
				var str = "";
				str += rid + ConstValues.strSpace + ConstValues.strLeftBracket + reportType + ConstValues.strRightBracket;
				strList.Add(str);
			});

			var essayArray = strList.ToArray();
			var essay = string.Join(ConstValues.chrSpace + ConstValues.strSemicolon + ConstValues.chrSpace, essayArray);

			//查询报告id
			var reportId = "";
			var reportList = await DbContext.ScheduleInfo.AsNoTracking().Where(x => personal.EssayId.Contains(x.ID.ToString())).ToListAsync();
			reportList.ForEach(x =>
			{
				if (reportId == "")
				{
					reportId += x.ID;
				}
				else
				{
					reportId += ConstValues.chrSpace + ConstValues.chrComma + ConstValues.chrSpace + x.ID;
				}
			});

			//查询费用明细
			var sql = from paymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking()
				.Where(x => x.AttendenceId == id)
				  join attInfo in DbContext.ConferenceAttendenceInfo.AsNoTracking()
					  on paymentInfo.AttendenceId equals attInfo.ID
				  join conferenceMaster2 in DbContext.ConferenceMaster.AsNoTracking()
					  on attInfo.ConferenceId equals conferenceMaster2.ID
				  select new ProfilePayInfoModel
				  {
					  FeeType = paymentInfo.FeeType,
					  FeeId = paymentInfo.FeeId,
					  FeeName = string.Empty,
					  Count = paymentInfo.Count,
					  Currency = paymentInfo.Currency,
					  Fee = paymentInfo.Fee,
					  Discount = paymentInfo.Discount,
					  BenefitEndDate = conferenceMaster2.BenefitEndDate,
					  BenefitStartDate = conferenceMaster2.BenefitStartDate
				  };
			var sqlResult = await sql.ToListAsync();
			sqlResult.ForEach(x =>
			{
				if (x.FeeType == ConstValues.FeeType.餐费)
				{
					x.FeeType = Resources.FeeMeal;

					x.FeeName = DbContext.FeeMealMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.参会费)
				{
					x.FeeType = Resources.FeeAttend;

					x.FeeName = DbContext.FeeAttendenceMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).RegisterType;
				}
				else if (x.FeeType == ConstValues.FeeType.版面费)
				{
					x.FeeType = Resources.FeePage;

					x.FeeName = DbContext.FeePageMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.其他费用)
				{
					x.FeeType = Resources.FeeOther;

					x.FeeName = DbContext.FeeOtherMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.同期活动费)
				{
					x.FeeType = Resources.ConferenceFeeEvent;
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					x.FeeName = DbContext.ConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
				}
			});
			List<string> feeDetailList = new List<string>();
			sqlResult.ForEach(x =>
			{
				var detailStr = "";
				detailStr += x.FeeType;
				detailStr += ConstValues.strSpace;
				detailStr += x.FeeName;
				detailStr += ConstValues.strSpace;
				detailStr += x.Currency;
				detailStr += ConstValues.chrSpace;
				if (isBenefit)
				{
					detailStr += x.Discount;
				}
				else
				{
					detailStr += x.Fee;
				}
				feeDetailList.Add(detailStr);
			});
			var feeDetail = string.Join("\\n", feeDetailList);

			//查询支付时间
			var paymentRecord = await DbContext.ProfilePaymentRecord.AsNoTracking().FirstOrDefaultAsync(x => x.AttendenceId == id && x.FeeStatus == true);
			var paymentTime = "";
			if (paymentRecord != null)
			{
				paymentTime = conferenceMaster.IsInternational ? paymentRecord.CreateDate.Value.ToString("yyyy-MM-dd HH:mm") : paymentRecord.CreateDate.Value.ToString("MM/dd/yyyy HH:mm");
			}

			model.FullName = personal.FullName;
			model.Affiliation = personal.Affiliation;
			model.Mail = personal.Mail;
			model.Tel = personal.Mobile;
			model.Country = conferenceMaster.IsInternational ?
					DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.NameEn :
					DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.Name;
			model.Essay = essay;
			model.Address = personal.Address;
			model.ZipCode = personal.ZipCode;
			model.Fee = personal.Currency + (isBenefit ? personal.Discount : personal.TotalFee).Value.ToString("N2");
			model.PayType = conferenceMaster.IsInternational ?
					DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentNameEn :
					DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentName;
			model.InvoiceTitle = personal.InvoiceTitle;
			model.InvoiceNum = personal.TaxNum;
			model.AddressAndTel = personal.AddressAndTel;
			model.Bank = personal.Bank;
			model.BankAccount = personal.BankAccount;
			model.BankAndAccount = personal.Bank + ConstValues.chrSpace + personal.BankAccount;
			model.TaxNum = personal.TaxNum;
			model.InvoiceId = personal.InvoiceId;
			model.InvoiceDetail = DbContext.ConferenceInvoiceMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.InvoiceId)?.InvoiceDetail;
			model.HotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.HotelId)?.HotelName;
			model.RoomType = DbContext.RoomMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.RoomTypeId)?.RoomType;
			model.ArrivalDate = personal.ArrivalDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.ArrivalDate.Value.ToString("MM/dd/yyyy") :
					personal.ArrivalDate.Value.ToString("yyyy-MM-dd")) : null;
			model.Creator = personal.Creator;
			model.DeparturalDate = personal.DeparturalDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.DeparturalDate.Value.ToString("MM/dd/yyyy") :
					personal.DeparturalDate.Value.ToString("yyyy-MM-dd")) : null;
			model.Id = personal.ID;
			model.ArrivalFlight = personal.ArrivalFlight;
			model.DeparturalFlight = personal.DeparturalFlight;
			model.Remark = string.IsNullOrEmpty(personal.Remark) ? string.Empty : personal.Remark.Replace("\r\n", "\\n");
			model.CreateDate = personal.CreateDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.CreateDate.Value.ToString("MM/dd/yyyy") :
					personal.CreateDate.Value.ToString("yyyy-MM-dd")) : null;
			model.HotelRemark = personal.HotelRemark;
			model.AttendenceIdentity = DbContext.AttendenceIdentityMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.AttendenceIdentityId)?.IdentityName;
			model.PaymentHasPay = personal.ActuallyFee.HasValue ? (personal.Currency + personal.ActuallyFee.Value.ToString("N2")) : string.Empty;
			model.HasPaid = personal.HasPaid == true ? Resources.HasPaid : Resources.HasNotPaid;
			model.FeeDetail = feeDetail;
			model.PaymentTime = paymentTime;
			model.ConferenceName = conferenceMaster.ConferenceName;
			model.AttendId = personal.ID;
			model.ReportId = reportId;
			model.Customize1 = personal.Customize1;
			model.Customize2 = personal.Customize2;
			model.Customize3 = personal.Customize3;
			model.Customize4 = personal.Customize4;
			model.Customize5 = personal.Customize5;
			model.CustomizeList = Utility.GetAttendenceCustomizeList(personal.ConferenceId);

			return View(model);
		}

		public async Task<ActionResult> IndexEn(string id)
		{
			var model = new ConferenceLocaleModel();

			var personal = await DbContext.ConferenceAttendenceInfo.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);
			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == personal.ConferenceId);

			var isBenefit = false;
			if (DateTime.Now >= conferenceMaster.BenefitStartDate && DateTime.Now <= conferenceMaster.BenefitEndDate)
			{
				isBenefit = true;
			}
			var payTypeId = DbContext.ConferencePaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.PaymentTypeId)?.PayId;

			//查询论文编号
			var essayList = await DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => personal.EssayId.Contains(x.ID.ToString()) &&
						x.EssayTitle != ConstValues.ChairmanReportCn &&
						x.EssayTitle != ConstValues.ChairmanReportEn)
					.ToListAsync();
			List<string> strList = new List<string>();
			essayList.ForEach(x =>
			{
				var reportType = DbContext.ReportMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.ReportId)?.ReportType;
				var rid = x.ID;
				var str = "";
				str += rid + ConstValues.strSpace + ConstValues.strLeftBracket + reportType + ConstValues.strRightBracket;
				strList.Add(str);
			});

			var essayArray = strList.ToArray();
			var essay = string.Join(ConstValues.chrSpace + ConstValues.strSemicolon + ConstValues.chrSpace, essayArray);

			//查询报告id
			var reportId = "";
			var reportList = await DbContext.ScheduleInfo.AsNoTracking().Where(x => personal.EssayId.Contains(x.ID.ToString())).ToListAsync();
			reportList.ForEach(x =>
			{
				if (reportId == "")
				{
					reportId += x.ID;
				}
				else
				{
					reportId += ConstValues.chrSpace + ConstValues.chrComma + ConstValues.chrSpace + x.ID;
				}
			});

			//查询费用明细
			var sql = from paymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking()
				.Where(x => x.AttendenceId == id)
				  join attInfo in DbContext.ConferenceAttendenceInfo.AsNoTracking()
					  on paymentInfo.AttendenceId equals attInfo.ID
				  join conferenceMaster2 in DbContext.ConferenceMaster.AsNoTracking()
					  on attInfo.ConferenceId equals conferenceMaster2.ID
				  select new ProfilePayInfoModel
				  {
					  FeeType = paymentInfo.FeeType,
					  FeeId = paymentInfo.FeeId,
					  FeeName = string.Empty,
					  Count = paymentInfo.Count,
					  Currency = paymentInfo.Currency,
					  Fee = paymentInfo.Fee,
					  Discount = paymentInfo.Discount,
					  BenefitEndDate = conferenceMaster2.BenefitEndDate,
					  BenefitStartDate = conferenceMaster2.BenefitStartDate
				  };
			var sqlResult = await sql.ToListAsync();
			sqlResult.ForEach(x =>
			{
				if (x.FeeType == ConstValues.FeeType.餐费)
				{
					x.FeeType = "Meal Fee";

					x.FeeName = DbContext.FeeMealMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.参会费)
				{
					x.FeeType = "Registration Fee";

					x.FeeName = DbContext.FeeAttendenceMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).RegisterType;
				}
				else if (x.FeeType == ConstValues.FeeType.版面费)
				{
					x.FeeType = "Publication Fee";

					x.FeeName = DbContext.FeePageMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.其他费用)
				{
					x.FeeType = "Other Fee";

					x.FeeName = DbContext.FeeOtherMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
				}
				else if (x.FeeType == ConstValues.FeeType.同期活动费)
				{
					x.FeeType = "ConcurrentEvent Fee";
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					x.FeeName = DbContext.ConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
				}
			});
			List<string> feeDetailList = new List<string>();
			sqlResult.ForEach(x =>
			{
				var detailStr = "";
				detailStr += x.FeeType;
				detailStr += ConstValues.strSpace;
				detailStr += x.FeeName;
				detailStr += ConstValues.strSpace;
				detailStr += x.Currency;
				detailStr += ConstValues.chrSpace;
				if (isBenefit)
				{
					detailStr += x.Discount;
				}
				else
				{
					detailStr += x.Fee;
				}
				feeDetailList.Add(detailStr);
			});
			var feeDetail = string.Join("\\n", feeDetailList);

			//查询支付时间
			var paymentRecord = await DbContext.ProfilePaymentRecord.AsNoTracking().FirstOrDefaultAsync(x => x.AttendenceId == id && x.FeeStatus == true);
			var paymentTime = "";
			if (paymentRecord != null)
			{
				paymentTime = conferenceMaster.IsInternational ? paymentRecord.CreateDate.Value.ToString("yyyy-MM-dd HH:mm") : paymentRecord.CreateDate.Value.ToString("MM/dd/yyyy HH:mm");
			}

			model.FullName = personal.FullName;
			model.Affiliation = personal.Affiliation;
			model.Mail = personal.Mail;
			model.Tel = personal.Mobile;
			model.Country = conferenceMaster.IsInternational ?
					DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.NameEn :
					DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.Name;
			model.Essay = essay;
			model.Address = personal.Address;
			model.ZipCode = personal.ZipCode;
			model.Fee = personal.Currency + (isBenefit ? personal.Discount : personal.TotalFee).Value.ToString("N2");
			model.PayType = conferenceMaster.IsInternational ?
					DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentNameEn :
					DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentName;
			model.InvoiceTitle = personal.InvoiceTitle;
			model.InvoiceNum = personal.TaxNum;
			model.AddressAndTel = personal.AddressAndTel;
			model.Bank = personal.Bank;
			model.BankAccount = personal.BankAccount;
			model.BankAndAccount = personal.Bank + ConstValues.chrSpace + personal.BankAccount;
			model.TaxNum = personal.TaxNum;
			model.InvoiceId = personal.InvoiceId;
			model.InvoiceDetail = DbContext.ConferenceInvoiceMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.InvoiceId)?.InvoiceDetail;
			model.HotelName = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.HotelId)?.HotelName;
			model.RoomType = DbContext.RoomMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.RoomTypeId)?.RoomType;
			model.ArrivalDate = personal.ArrivalDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.ArrivalDate.Value.ToString("MM/dd/yyyy") :
					personal.ArrivalDate.Value.ToString("yyyy-MM-dd")) : null;
			model.Creator = personal.Creator;
			model.DeparturalDate = personal.DeparturalDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.DeparturalDate.Value.ToString("MM/dd/yyyy") :
					personal.DeparturalDate.Value.ToString("yyyy-MM-dd")) : null;
			model.Id = personal.ID;
			model.ArrivalFlight = personal.ArrivalFlight;
			model.DeparturalFlight = personal.DeparturalFlight;
			model.Remark = string.IsNullOrEmpty(personal.Remark) ? string.Empty : personal.Remark.Replace("\r\n", "\\n");
			model.CreateDate = personal.CreateDate.HasValue ? (conferenceMaster.IsInternational ?
					personal.CreateDate.Value.ToString("MM/dd/yyyy") :
					personal.CreateDate.Value.ToString("yyyy-MM-dd")) : null;
			model.HotelRemark = personal.HotelRemark;
			model.AttendenceIdentity = DbContext.AttendenceIdentityMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.AttendenceIdentityId)?.IdentityName;
			model.PaymentHasPay = personal.ActuallyFee.HasValue ? (personal.Currency + personal.ActuallyFee.Value.ToString("N2")) : string.Empty;
			model.HasPaid = personal.HasPaid == true ? "Has Paid" : "Has Not Paid";
			model.FeeDetail = feeDetail;
			model.PaymentTime = paymentTime;
			model.ConferenceName = conferenceMaster.ConferenceName;
			model.AttendId = personal.ID;
			model.ReportId = reportId;
			model.Customize1 = personal.Customize1;
			model.Customize2 = personal.Customize2;
			model.Customize3 = personal.Customize3;
			model.Customize4 = personal.Customize4;
			model.Customize5 = personal.Customize5;
			model.CustomizeList = Utility.GetAttendenceCustomizeList(personal.ConferenceId);

			return View(model);
		}

		/// <summary>
		/// 报告人
		/// cheng
		/// </summary>
		public async Task<JsonCamelCaseResult> GetPresenterList(string conferenceId)
		{
			//张贴报告录用，确认出席；口头报告已安排
			var sql = from author in DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId)
				  join contributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					  .Where(x => x.ConferenceId == conferenceId)
					  on author.ContributeId equals contributeInfo.ID
				  join reportMaster in DbContext.ReportMaster.AsNoTracking()
					  on contributeInfo.ReportId equals reportMaster.ID
				  where ((reportMaster.ReportType == ConstValues.PosterCn || reportMaster.ReportType == ConstValues.PosterEn) && contributeInfo.IsConfirm == true
							 && author.Status == ConstValues.Status.正常 && (!string.IsNullOrEmpty(contributeInfo.AdminStatus) ? contributeInfo.AdminStatus == ConstValues.ContributationStatus.录用 :
						contributeInfo.ContributationStatus == ConstValues.ContributationStatus.录用)) ||
					    ((reportMaster.ReportType != ConstValues.PosterCn && reportMaster.ReportType != ConstValues.PosterEn)
							&& contributeInfo.ScheduleStatus == ConstValues.ScheduleStatus.已安排 && author.Status == ConstValues.Status.正常)
				  group author by new { Name = author.FullName, Mail = author.Mail, FamilyName = author.FamilyName, ContributeId = author.ContributeId, } into g1
				  select new
				  {
					  FullName = g1.Key.Name,
					  Mail = g1.Key.Mail,
					  FamilyName = g1.Key.FamilyName,
					  ContributeId = g1.Key.ContributeId
				  };

			var sqlResult = await sql.ToListAsync();

			var conferenceMaster = await DbContext.ConferenceMaster.FirstOrDefaultAsync(x => x.ID == conferenceId);

			if (sqlResult.Count > 0)
			{
				var result = sqlResult.Select(x => new
				{
					Mail = x.Mail,
					FullName = x.FullName,
					FamilyName = x.FamilyName,
					Affiliation = getAllAffiliation(conferenceId, x.Mail),
					Name = DbContext.AffiliationInfo.FirstOrDefault(y => y.Mail == x.Mail && y.ConferenceId == conferenceId) == null ?
							x.FullName :
							x.FullName + ConstValues.strComma + DbContext.AffiliationInfo.OrderBy(y => y.CreateDate).ThenBy(y => y.Sort).FirstOrDefault(y => y.Mail == x.Mail && y.ConferenceId == conferenceId).Affiliation,
					NameAndAffiliation = DbContext.AffiliationInfo.FirstOrDefault(y => y.Mail == x.Mail && y.ConferenceId == conferenceId) == null ?
							string.Empty :
							(conferenceMaster.IsInternational ? (x.FullName + Utility.GetAllAffiliationEn(conferenceId, x.Mail, x.ContributeId, ConstValues.strComma)).Replace(x.FullName + ConstValues.strComma, string.Empty) :
								(x.FullName + Utility.GetAllAffiliation(conferenceId, x.Mail, x.ContributeId, ConstValues.strCommaCn)).Replace(x.FullName + ConstValues.strCommaCn, string.Empty))
				});
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public static string getAllAffiliation(string conferenceId, string mail)
		{
			var DbContext = new CISEntities();
			var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == conferenceId &&
							x.Mail == mail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => x.Affiliation)
						.Distinct()
						.ToList();
			var affiliation = affiliationList.Count > 0 ? string.Join(ConstValues.strSemicolon, affiliationList) : string.Empty;
			return affiliation;
		}

		public async Task<JsonResult> GetCurrency(string conferenceId)
		{
			var sql = DbContext.FeeAttendenceMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId &&
						x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key)
					.Union(DbContext.FeeMealMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key))
					.Union(DbContext.FeeOtherMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key))
					.Union(DbContext.FeePageMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.GroupBy(x => x.Currency).Select(x => x.Key))
					.Union(DbContext.HotelMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.Join(DbContext.RoomMaster.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常),
							hotel => hotel.ID,
							room => room.HotelId,
							(hotel, room) => new
							{
								Currency = room.Currency
							}
						)
						.GroupBy(x => x.Currency).Select(x => x.Key))
					.Union(DbContext.ConcurrentEventMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.Join(DbContext.FeeConcurrentEventMaster.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常),
							conevent => conevent.ID,
							eventFee => eventFee.ConcurrentEventId,
							(conevent, eventFee) => new
							{
								Currency = eventFee.Currency
							}
						)
						.GroupBy(x => x.Currency).Select(x => x.Key));
			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Currency = x.ToString()
			});
			if (result != null)
			{
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 第一页
		/// 移动端获取会议总日程信息
		/// zyq
		/// </summary>
		public async Task<JsonCamelCaseResult> GetScheduleMainList(string conferenceId, string data)
		{
			var sql = DbContext.ViewScheduleContribute.AsNoTracking().Where(x =>
						x.ConferenceId == conferenceId && x.ScheduleDate.ToString() == data)
					.GroupBy(x => new { x.FLG, x.FirstName, x.Sort })
					.Select(x => new
					{
						Name = x.Key.FirstName,
						Flg = x.Key.FLG,
						Sort = x.Key.Sort,
						StartTime = x.Min(y => y.StartTime),
						EndTime = x.Max(y => y.EndTime),
						SchedulePlace = x.Max(y => y.SchedulePlace),
						IsContribute = x.Any(y => y.IsContribute),
						TopicId = x.Max(y => y.TopicId)
					})
					.OrderBy(x => x.Sort).ThenBy(x => x.Flg).ThenBy(x => x.StartTime).ThenBy(x => x.EndTime);

			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				Name = x.Name,
				Flg = x.Flg,
				ScheduleData = x.StartTime.ToString().Substring(0, 5) + ConstValues.chrHyphen +
							x.EndTime.ToString().Substring(0, 5),
				SchedulePlace = x.SchedulePlace,
				IsContribute = x.IsContribute,
				TopicId = x.TopicId
			});
			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		/// <summary>
		/// 第二页
		/// 移动端获取会议日程报告信息
		/// zyq
		/// </summary>
		public async Task<JsonCamelCaseResult> GetReportList(string flg, string date, string topicId)
		{
			var sql = from scheduleInfo in DbContext.ViewScheduleContribute.AsNoTracking().Where(x =>
						x.FLG == flg.Replace("~", " ") && x.ScheduleDate.ToString() == date && x.TopicId == topicId)
				  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					  on scheduleInfo.ContributeId equals conferenceContributeInfo.ID into t1
				  from contribute in t1.DefaultIfEmpty()
				  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
					  on contribute.ID equals authorInfo.ContributeId into t2
				  from author in t2.DefaultIfEmpty()
				  orderby scheduleInfo.StartTime, scheduleInfo.EndTime
				  select new
				  {
					  Id = scheduleInfo.ID,
					  ReportType = scheduleInfo.ReportType,
					  TopicId = scheduleInfo.TopicId,
					  TopicName = scheduleInfo.FirstName,
					  ContributeId = scheduleInfo.IsContribute ? scheduleInfo.ContributeId : string.Empty,
					  ScheduleEventId = scheduleInfo.IsContribute ? string.Empty : scheduleInfo.ContributeId,
					  EssayTitle = scheduleInfo.SecondName,
					  Presenter = scheduleInfo.IsContribute ? author.FullName : scheduleInfo.Presenter,
					  //Affiliation = author.Affiliation,
					  Country = author.Country,
					  Mail = author.Mail,
					  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
					  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
					  IsContribute = scheduleInfo.IsContribute,
					  Remark = scheduleInfo.Remark,
					  ConferenceId = scheduleInfo.ConferenceId,
					  FullName = author.FullName,
					  ScheduleDate = scheduleInfo.ScheduleDate,
					  Status = scheduleInfo.Status,
					  SchedulePlace = scheduleInfo.SchedulePlace,
					  ChairmanMail = scheduleInfo.ChairmanMail,
					  IsInternational = scheduleInfo.IsInternational,
					  ConferenceName = scheduleInfo.ConferenceName,
					  ConferenceNickName = scheduleInfo.ConferenceNickName
				  };

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == y.ConferenceId &&
						x.ContributeId == y.ContributeId &&
						x.Mail == y.Mail)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Affiliation)
					.Select(x => x.Affiliation)
					.ToList();
				var strAffiliation = affiliationList.Count > 0 ? string.Join(ConstValues.strSemicolon, affiliationList) : string.Empty;

				var authorList = DbContext.AuthorInfo.AsNoTracking()
					.Where(x => x.ContributeId == y.Id &&
						x.ConferenceId == y.ConferenceId)
					.OrderBy(x => x.Sort)
					.Select(x => x.FullName);

				//取主持人的单位和国家
				var chairmanAffiliation = "";
				var chairmanCountry = "";

				var affiliationAndCountry = "";
				if (y.IsContribute)
				{
					if (y.IsInternational)
					{
						affiliationAndCountry = Utility.GetAllAffiliationEn(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strComma);
					}
					else
					{
						affiliationAndCountry = Utility.GetAllAffiliation(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strCommaCn);
					}
				}
				else
				{
					chairmanAffiliation = DbContext.AffiliationInfo.AsNoTracking().FirstOrDefault(x => x.Mail == y.ChairmanMail)?.Affiliation;
					var tempCountryId = DbContext.AffiliationInfo.AsNoTracking().FirstOrDefault(x => x.Mail == y.ChairmanMail)?.Country;
					if (tempCountryId != null)
					{
						chairmanCountry = DbContext.LocationMaster.FirstOrDefault(z => z.ID == tempCountryId)?.NameEn;
					}
					if (y.IsInternational)
					{
						affiliationAndCountry = chairmanAffiliation + (string.IsNullOrEmpty(chairmanCountry) ? string.Empty : ConstValues.strComma + chairmanCountry);
					}
					else
					{
						affiliationAndCountry = chairmanAffiliation;
					}
				}

				result.Add(new ConferenceScheduleReportModel()
				{
					Id = y.Id,
					ReportType = y.ReportType,
					TopicName = y.TopicName,
					ContributeId = y.ContributeId,
					EssayTitle = y.IsContribute ? y.EssayTitle : Utility.GetScheduleEventNameById(y.ScheduleEventId),
					FullName = string.IsNullOrEmpty(y.FullName) ? string.Empty : y.FullName,
					Affiliation = y.IsContribute ?
								(string.IsNullOrEmpty(strAffiliation) ? string.Empty : strAffiliation) :
								(string.IsNullOrEmpty(chairmanAffiliation) ? string.Empty : chairmanAffiliation),
					Country = y.IsContribute ?
								(y.Country == null ? string.Empty : DbContext.LocationMaster.FirstOrDefault(z => z.ID == y.Country)?.NameEn) :
								(string.IsNullOrEmpty(chairmanCountry) ? string.Empty : chairmanCountry),
					Author = authorList.ToList().Count > 0 ? string.Join(ConstValues.strSemicolon, authorList) : string.Empty,
					StartTime = y.StartTime,
					EndTime = y.EndTime,
					IsContribute = y.IsContribute,
					Remark = y.Remark,
					Presenter = string.IsNullOrEmpty(y.Presenter) ? string.Empty : y.Presenter,
					ScheduleDate = y.ScheduleDate,
					ConferenceName = y.ConferenceName,
					Status = y.Status,
					ConferenceId = y.ConferenceId,
					SchedulePlace = y.SchedulePlace,
					ConferenceNickName = y.ConferenceNickName,
					AffiliationAndCountry = affiliationAndCountry
				});
			});

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);

		}

		//通过邮箱取报告人头像
		public async Task<JsonCamelCaseResult> GetPresenterImgByMail(string mail)
		{
			var data = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.Mail == mail);

			var folder = ConstValues.SystemWeb + ConstValues.UserHeadImg.Replace(ConstValues.strWave, string.Empty);

			if (data != null && data.HeadImg != null)
			{
				var result = new
				{
					Id = data.ID,
					HeadImg = folder + Path.GetFileName(data.HeadImg),
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取报告人的所有报告
		//第四页
		public async Task<JsonCamelCaseResult> GetPresenterReport(string conferenceId, string mail, string fullName)
		{
			var sql = from authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.ConferenceId == conferenceId
					&& x.Mail == mail && x.FullName == fullName.Replace("~", " "))
				  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => x.EssayTitle != ConstValues.ChairmanReportCn &&
						x.EssayTitle != ConstValues.ChairmanReportEn)
					  on authorInfo.ContributeId equals conferenceContributeInfo.ID into t1
				  from contribute in t1.DefaultIfEmpty()
				  join scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
				   on authorInfo.ContributeId equals scheduleInfo.ContributeId into t2
				  from schedule in t2.DefaultIfEmpty()
				  join topicMaster in DbContext.TopicMaster.AsNoTracking()
				   on contribute.TopicId equals topicMaster.ID into t3
				  from topic in t3.DefaultIfEmpty()
				  join scheduleMaster in DbContext.ScheduleMaster.AsNoTracking()
				   on schedule.ScheduleId equals scheduleMaster.ID into t4
				  from sceduleMst in t4.DefaultIfEmpty()
				  join reportMaster in DbContext.ReportMaster.AsNoTracking()
				   on contribute.ReportId equals reportMaster.ID into t5
				  from report in t5.DefaultIfEmpty()
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
				  on contribute.ConferenceId equals conferenceMaster.ID into t6
				  from conference in t6.DefaultIfEmpty()
				  orderby schedule.ScheduleDate, schedule.StartTime
				  select new
				  {
					  Id = schedule.ID,
					  ScheduleDate = schedule.ScheduleDate.ToString(),
					  StartTime = schedule.StartTime.ToString().Substring(0, 5),
					  EndTime = schedule.EndTime.ToString().Substring(0, 5),
					  EssayTitle = contribute.EssayTitle,
					  ContributeId = contribute.ID,
					  Status = schedule.Status,
					  TopicId = topic.ID,
					  TopicName = topic.TopicName,
					  ReportId = report.ID,
					  ReportType = report.ReportType,
					  SchedulePlace = sceduleMst.SchedulePlace,
					  ConferenceName = conference.ConferenceName,
					  ConferenceNickName = conference.ConferenceNickName,
					  ConferenceId = conference.ID,
					  IsInternational = conference.IsInternational,
				  };

			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				Id = string.IsNullOrEmpty(x.Id) ? x.ContributeId : x.Id,
				ScheduleDate = !string.IsNullOrEmpty(x.ScheduleDate) ? x.ScheduleDate : string.Empty,
				StartTime = !string.IsNullOrEmpty(x.StartTime) ? x.StartTime : string.Empty,
				EndTime = !string.IsNullOrEmpty(x.EndTime) ? x.EndTime : string.Empty,
				EssayTitle = x.EssayTitle,
				Presenter = DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter) == null ?
							string.Empty :
							DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.FullName,
				Affiliation = x.IsInternational ?
						Utility.GetAllAffiliationEn(x.ConferenceId, DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.Mail, x.ContributeId, ConstValues.strComma) :
						Utility.GetAllAffiliation(x.ConferenceId, DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.Mail, x.ContributeId, ConstValues.strCommaCn),

				Status = string.IsNullOrEmpty(x.Status) ? string.Empty : x.Status,
				ContributeId = x.ContributeId,
				TopicName = string.IsNullOrEmpty(x.TopicName) ? string.Empty : x.TopicName,
				ReportType = string.IsNullOrEmpty(x.ReportType) ? string.Empty : x.ReportType,
				SchedulePlace = !string.IsNullOrEmpty(x.SchedulePlace) ? x.SchedulePlace : string.Empty,
				ConferenceName = x.ConferenceName,
				ConferenceNickName = x.ConferenceNickName,
				ConferenceId = x.ConferenceId
			});
			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//报告详情页面获取报告人的所有报告
		public async Task<JsonCamelCaseResult> GetPresenterAllReport(string conferenceId, string mail, string fullName)
		{
			var sql = from authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.ConferenceId == conferenceId
					&& x.Mail == mail && x.FullName == fullName.Replace("~", " "))
				  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => x.EssayTitle != ConstValues.ChairmanReportCn &&
						x.EssayTitle != ConstValues.ChairmanReportEn)
					  on authorInfo.ContributeId equals conferenceContributeInfo.ID into t1
				  from contribute in t1.DefaultIfEmpty()
				  join scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
				   on authorInfo.ContributeId equals scheduleInfo.ContributeId into t2
				  from schedule in t2.DefaultIfEmpty()
				  join topicMaster in DbContext.TopicMaster.AsNoTracking()
				   on contribute.TopicId equals topicMaster.ID into t3
				  from topic in t3.DefaultIfEmpty()
				  join scheduleMaster in DbContext.ScheduleMaster.AsNoTracking()
				   on schedule.ScheduleId equals scheduleMaster.ID into t4
				  from sceduleMst in t4.DefaultIfEmpty()
				  join reportMaster in DbContext.ReportMaster.AsNoTracking()
				   on contribute.ReportId equals reportMaster.ID into t5
				  from report in t5.DefaultIfEmpty()
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
				  on contribute.ConferenceId equals conferenceMaster.ID into t6
				  from conference in t6.DefaultIfEmpty()
				  orderby schedule.ScheduleDate, schedule.StartTime
				  select new
				  {
					  Id = schedule.ID,
					  ScheduleDate = schedule.ScheduleDate.ToString(),
					  StartTime = schedule.StartTime.ToString().Substring(0, 5),
					  EndTime = schedule.EndTime.ToString().Substring(0, 5),
					  EssayTitle = contribute.EssayTitle,
					  ContributeId = contribute.ID,
					  Status = schedule.Status,
					  TopicId = topic.ID,
					  TopicName = topic.TopicName,
					  ReportId = report.ID,
					  ReportType = report.ReportType,
					  SchedulePlace = sceduleMst.SchedulePlace,
					  IsInternational = conference.IsInternational,
					  ConferenceId = contribute.ConferenceId
				  };


			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				Id = x.Id,
				ScheduleDate = x.ScheduleDate,
				StartTime = !string.IsNullOrEmpty(x.StartTime) ? x.StartTime : string.Empty,
				EndTime = !string.IsNullOrEmpty(x.EndTime) ? x.EndTime : string.Empty,
				EssayTitle = x.EssayTitle,
				Presenter = DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter) == null ?
							string.Empty :
							DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.FullName,
				Affiliation = x.IsInternational ?
						Utility.GetAllAffiliationEn(x.ConferenceId, DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.Mail, x.ContributeId, ConstValues.strComma) :
						Utility.GetAllAffiliation(x.ConferenceId, DbContext.AuthorInfo.FirstOrDefault(y => y.ContributeId == x.ContributeId && y.IsPresenter)?.Mail, x.ContributeId, ConstValues.strCommaCn),

				Status = x.Status,
				ContributeId = x.ContributeId,
				TopicName = x.TopicName,
				ReportType = string.IsNullOrEmpty(x.ReportType) ? string.Empty : x.ReportType,
				SchedulePlace = !string.IsNullOrEmpty(x.SchedulePlace) ? x.SchedulePlace : string.Empty,
			});
			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		/// <summary>
		/// 会议专题下拉
		/// cheng
		/// </summary>
		public async Task<JsonResult> GetTopicMobile(string conferenceId)
		{
			var sql = DbContext.TopicMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.TopicName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.TopicName
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 会议专题下拉
		/// cheng
		/// </summary>
		public async Task<JsonResult> GetReportTypeMobile(string conferenceId)
		{
			var sql = DbContext.ReportMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.ReportType);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.ReportType
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 专题日程
		/// cheng
		/// </summary>
		public async Task<JsonCamelCaseResult> GetReportListByTopicName(string conferenceId, string topicId, string date)
		{
			if (conferenceId != null && topicId != null && date != null)
			{
				var sql = from scheduleInfo in DbContext.ViewScheduleContribute.AsNoTracking().Where(x =>
							x.ConferenceId == conferenceId && x.TopicId == topicId && x.ScheduleDate.ToString() == date)
					  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
						  on scheduleInfo.ContributeId equals conferenceContributeInfo.ID into t1
					  from contribute in t1.DefaultIfEmpty()
					  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
						  on contribute.ID equals authorInfo.ContributeId into t2
					  from author in t2.DefaultIfEmpty()
					  orderby scheduleInfo.StartTime, scheduleInfo.EndTime, scheduleInfo.Sort
					  select new
					  {
						  Id = scheduleInfo.ID,
						  ReportType = scheduleInfo.ReportType,
						  TopicId = scheduleInfo.TopicId,
						  TopicName = scheduleInfo.FirstName,
						  ContributeId = scheduleInfo.IsContribute ? scheduleInfo.ContributeId : string.Empty,
						  ScheduleEventId = scheduleInfo.IsContribute ? string.Empty : scheduleInfo.ContributeId,
						  EssayTitle = scheduleInfo.SecondName,
						  Presenter = scheduleInfo.IsContribute ? author.FullName : scheduleInfo.Presenter,
						  //Affiliation = author.Affiliation,
						  Country = author.Country,
						  Mail = author.Mail,
						  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
						  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
						  IsContribute = scheduleInfo.IsContribute,
						  Remark = scheduleInfo.Remark,
						  ConferenceId = scheduleInfo.ConferenceId,
						  FullName = author.FullName,
						  ScheduleDate = scheduleInfo.ScheduleDate,
						  Status = scheduleInfo.Status,
						  SchedulePlace = scheduleInfo.SchedulePlace,
						  ChairmanMail = scheduleInfo.ChairmanMail,
						  IsInternational = scheduleInfo.IsInternational,
						  ConferenceName = scheduleInfo.ConferenceName,
						  ConferenceNickName = scheduleInfo.ConferenceNickName
					  };

				var sqlResult = await sql.ToListAsync();

				var result = new List<ConferenceScheduleReportModel>();
				sqlResult.ForEach(y =>
				{
					var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.ContributeId == y.ContributeId &&
							x.Mail == y.Mail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => x.Affiliation)
						.ToList();
					var strAffiliation = affiliationList.Count > 0 ? string.Join(ConstValues.strSemicolon, affiliationList) : string.Empty;

					var authorList = DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ContributeId == y.Id &&
							x.ConferenceId == y.ConferenceId)
						.OrderBy(x => x.Sort)
						.Select(x => x.FullName);

					//取主持人的单位和国家
					var chairmanCountry = "";
					if (!y.IsContribute)
					{
						var tempCountryId = DbContext.AuthorInfo.AsNoTracking().FirstOrDefault(x => x.Mail == y.ChairmanMail)?.Country;
						if (tempCountryId != null)
						{
							chairmanCountry = DbContext.LocationMaster.FirstOrDefault(z => z.ID == tempCountryId).NameEn;
						}
					}

					var affiliationAndCountry = string.Empty;
					if (!y.IsContribute)
					{
						var eventMaster = DbContext.ScheduleEventMaster.AsNoTracking().FirstOrDefault(x => x.ID == y.ScheduleEventId);
						affiliationAndCountry = y.IsInternational ?
									Utility.GetAllAffiliationEn(y.ConferenceId, y.ChairmanMail, eventMaster.ContributeId, ConstValues.strComma) :
									Utility.GetAllAffiliation(y.ConferenceId, y.ChairmanMail, eventMaster.ContributeId, ConstValues.strCommaCn);
					}
					else
					{
						affiliationAndCountry = y.IsInternational ?
										Utility.GetAllAffiliationEn(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strComma) :
										Utility.GetAllAffiliation(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strCommaCn);
					}

					result.Add(new ConferenceScheduleReportModel()
					{
						Id = y.Id,
						ReportType = string.IsNullOrEmpty(y.ReportType) ? string.Empty : y.ReportType,
						TopicId = y.TopicId,
						TopicName = y.TopicName,
						ContributeId = y.ContributeId,
						EssayTitle = y.IsContribute ? y.EssayTitle : Utility.GetScheduleEventNameById(y.ScheduleEventId),
						FullName = string.IsNullOrEmpty(y.FullName) ? string.Empty : y.FullName,
						Affiliation = strAffiliation,
						Country = y.IsContribute ?
								(y.Country == null ? string.Empty : DbContext.LocationMaster.FirstOrDefault(z => z.ID == y.Country)?.NameEn) :
								(string.IsNullOrEmpty(chairmanCountry) ? string.Empty : chairmanCountry),
						Author = authorList.ToList().Count > 0 ? string.Join(ConstValues.strSemicolon, authorList) : string.Empty,
						StartTime = y.StartTime,
						EndTime = y.EndTime,
						IsContribute = y.IsContribute,
						Remark = y.Remark,
						Presenter = string.IsNullOrEmpty(y.Presenter) ? string.Empty : y.Presenter,
						ScheduleDateMobile = y.IsInternational ? y.ScheduleDate.ToString("dd-yyyy-MM") : y.ScheduleDate.ToString("yyyy-MM-dd"),
						Status = y.Status,
						SchedulePlace = y.SchedulePlace,
						ScheduleTime = date,
						ConferenceName = y.ConferenceName,
						ConferenceNickName = y.ConferenceNickName,
						AffiliationAndCountry = affiliationAndCountry,

					});
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "false"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonCamelCaseResult> GetAllReportList(string conferenceId, string date)
		{
			if (conferenceId != null && date != null)
			{
				var sql = from scheduleInfo in DbContext.ViewScheduleContribute.AsNoTracking().Where(x =>
							x.ConferenceId == conferenceId && x.ScheduleDate.ToString() == date)
					  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
						  on scheduleInfo.ContributeId equals conferenceContributeInfo.ID into t1
					  from contribute in t1.DefaultIfEmpty()
					  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
						  on contribute.ID equals authorInfo.ContributeId into t2
					  from author in t2.DefaultIfEmpty()
					  orderby scheduleInfo.StartTime, scheduleInfo.EndTime, scheduleInfo.Sort, scheduleInfo.FLG
					  select new
					  {
						  Id = scheduleInfo.ID,
						  ReportType = scheduleInfo.ReportType,
						  TopicId = scheduleInfo.TopicId,
						  TopicName = scheduleInfo.FirstName,
						  ContributeId = scheduleInfo.IsContribute ? scheduleInfo.ContributeId : string.Empty,
						  ScheduleEventId = scheduleInfo.IsContribute ? string.Empty : scheduleInfo.ContributeId,
						  EssayTitle = scheduleInfo.SecondName,
						  Presenter = scheduleInfo.IsContribute ? author.FullName : scheduleInfo.Presenter,
						  //Affiliation = author.Affiliation,
						  Country = author.Country,
						  Mail = author.Mail,
						  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
						  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
						  IsContribute = scheduleInfo.IsContribute,
						  Remark = scheduleInfo.Remark,
						  ConferenceId = scheduleInfo.ConferenceId,
						  FullName = author.FullName,
						  ScheduleDate = scheduleInfo.ScheduleDate,
						  Status = scheduleInfo.Status,
						  SchedulePlace = scheduleInfo.SchedulePlace,
						  ChairmanMail = scheduleInfo.ChairmanMail,
						  IsInternational = scheduleInfo.IsInternational,
						  ConferenceName = scheduleInfo.ConferenceName,
						  ConferenceNickName = scheduleInfo.ConferenceNickName
					  };

				var sqlResult = await sql.ToListAsync();

				var result = new List<ConferenceScheduleReportModel>();
				sqlResult.ForEach(y =>
				{
					var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.ContributeId == y.ContributeId &&
							x.Mail == y.Mail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => x.Affiliation)
						.ToList();
					var strAffiliation = affiliationList.Count > 0 ? string.Join(ConstValues.strSemicolon, affiliationList) : string.Empty;

					var authorList = DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ContributeId == y.Id &&
							x.ConferenceId == y.ConferenceId)
						.OrderBy(x => x.Sort)
						.Select(x => x.FullName);

					//取主持人的单位和国家
					//var chairmanAffiliation = "";
					var chairmanCountry = "";
					if (!y.IsContribute)
					{
						var tempCountryId = DbContext.AuthorInfo.AsNoTracking().FirstOrDefault(x => x.Mail == y.ChairmanMail)?.Country;
						if (tempCountryId != null)
						{
							chairmanCountry = DbContext.LocationMaster.FirstOrDefault(z => z.ID == tempCountryId)?.NameEn;
						}
					}

					var affiliationAndCountry = string.Empty;
					if (!y.IsContribute)
					{
						var eventMaster = DbContext.ScheduleEventMaster.AsNoTracking().FirstOrDefault(x => x.ID == y.ScheduleEventId);
						affiliationAndCountry = y.IsInternational ?
									Utility.GetAllAffiliationEn(y.ConferenceId, y.ChairmanMail, eventMaster.ContributeId, ConstValues.strComma) :
									Utility.GetAllAffiliation(y.ConferenceId, y.ChairmanMail, eventMaster.ContributeId, ConstValues.strCommaCn);
					}
					else
					{
						affiliationAndCountry = y.IsInternational ?
										Utility.GetAllAffiliationEn(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strComma) :
										Utility.GetAllAffiliation(y.ConferenceId, y.Mail, y.ContributeId, ConstValues.strCommaCn);
					}

					result.Add(new ConferenceScheduleReportModel()
					{
						Id = y.Id,
						ReportType = string.IsNullOrEmpty(y.ReportType) ? string.Empty : y.ReportType,
						TopicId = y.TopicId,
						TopicName = y.TopicName,
						ContributeId = y.ContributeId,
						EssayTitle = y.IsContribute ? y.EssayTitle : Utility.GetScheduleEventNameById(y.ScheduleEventId),
						FullName = string.IsNullOrEmpty(y.FullName) ? string.Empty : y.FullName,
						//Affiliation = y.IsContribute ?
						//			(string.IsNullOrEmpty(strAffiliation) ? string.Empty : strAffiliation) :
						//			(string.IsNullOrEmpty(chairmanAffiliation) ? string.Empty : chairmanAffiliation),
						Affiliation = strAffiliation,
						Author = authorList.ToList().Count > 0 ? string.Join(ConstValues.strSemicolon, authorList) : string.Empty,
						Country = y.IsContribute ?
								(y.Country == null ? string.Empty : DbContext.LocationMaster.FirstOrDefault(z => z.ID == y.Country)?.NameEn) :
								(string.IsNullOrEmpty(chairmanCountry) ? string.Empty : chairmanCountry),
						StartTime = y.StartTime,
						EndTime = y.EndTime,
						IsContribute = y.IsContribute,
						Remark = y.Remark,
						Presenter = string.IsNullOrEmpty(y.Presenter) ? string.Empty : y.Presenter,
						ScheduleDateMobile = y.IsInternational ? y.ScheduleDate.ToString("dd-yyyy-MM") : y.ScheduleDate.ToString("yyyy-MM-dd"),
						Status = y.Status,
						SchedulePlace = y.SchedulePlace,
						ScheduleTime = date,
						ConferenceName = y.ConferenceName,
						ConferenceNickName = y.ConferenceNickName,
						AffiliationAndCountry = affiliationAndCountry,
					});
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "false"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取参会注册表单
		public async Task<JsonCamelCaseResult> GetConferenceAttendenceFormMobile(string conferenceId)
		{
			var sql = DbContext.ConferenceAttendenceForm.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.IsDisplayMobile == true)
				.OrderBy(x => x.DisplayPage)
				.ThenBy(x => x.Sort);
			var sqlResult = await sql.ToListAsync();

			if (sqlResult != null)
			{
				var sqlCurrency = DbContext.FeeAttendenceMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key)
						.Union(DbContext.FeeMealMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.FeeOtherMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.FeePageMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.HotelMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.Join(DbContext.RoomMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常),
								hotel => hotel.ID,
								room => room.HotelId,
								(hotel, room) => new
								{
									Currency = room.Currency
								}
							)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.ConcurrentEventMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.Join(DbContext.FeeConcurrentEventMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常),
								conevent => conevent.ID,
								eventFee => eventFee.ConcurrentEventId,
								(conevent, eventFee) => new
								{
									Currency = eventFee.Currency
								}
							)
							.GroupBy(x => x.Currency).Select(x => x.Key));

				var sqlCurrencyResult = await sqlCurrency.ToListAsync();

				if (sqlCurrencyResult.Count == 0)
				{
					var paymentType = sqlResult.FirstOrDefault(x => x.Key == "PaymentType");
					sqlResult.Remove(paymentType);
				}

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					ConferenceId = x.ConferenceId,
					Key = x.Key,
					DisplayName = x.DisplayName,
					Tips = !string.IsNullOrEmpty(x.Tip) ? x.Tip : string.Empty,
					IsRequire = x.IsRequired,
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取参会注册表单
		public async Task<JsonCamelCaseResult> GetConferenceAttendenceFormIOS(string conferenceId)
		{
			var sql = DbContext.ConferenceAttendenceForm.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.IsDisplayMobile == true &&
					x.Key != "Visa" && x.Key != "Recommend")
				.OrderBy(x => x.DisplayPage)
				.ThenBy(x => x.Sort);

			var sqlResult = await sql.ToListAsync();
			if (sqlResult != null)
			{
				var sqlCurrency = DbContext.FeeAttendenceMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key)
						.Union(DbContext.FeeMealMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.FeeOtherMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.FeePageMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.HotelMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.Join(DbContext.RoomMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常),
								hotel => hotel.ID,
								room => room.HotelId,
								(hotel, room) => new
								{
									Currency = room.Currency
								}
							)
							.GroupBy(x => x.Currency).Select(x => x.Key))
						.Union(DbContext.ConcurrentEventMaster.AsNoTracking()
							.Where(x => x.ConferenceId == conferenceId &&
								x.Status == ConstValues.Status.正常)
							.Join(DbContext.FeeConcurrentEventMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常),
								conevent => conevent.ID,
								eventFee => eventFee.ConcurrentEventId,
								(conevent, eventFee) => new
								{
									Currency = eventFee.Currency
								}
							)
							.GroupBy(x => x.Currency).Select(x => x.Key));

				var sqlCurrencyResult = await sqlCurrency.ToListAsync();

				var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == conferenceId);
				if (sqlCurrencyResult.Count > 0)
				{
					sqlResult.Insert(1, new ConferenceAttendenceForm
					{
						ID = string.Empty,
						ConferenceId = conferenceId,
						Key = "Currency",
						DisplayName = conferenceMaster.IsInternational ? "Currency" : "币种",
						Tip = conferenceMaster.IsInternational ? "Currency" : "币种",
						IsRequired = true,
					});
				}
				else
				{
					var paymentType = sqlResult.FirstOrDefault(x => x.Key == "PaymentType");
					sqlResult.Remove(paymentType);
				}

				for (var i = 0; i < sqlResult.Count; i++)
				{
					if (sqlResult[i].Key == "Country")
					{
						int idx = sqlResult.IndexOf(sqlResult[i]);
						sqlResult.Insert(idx + 1, new ConferenceAttendenceForm
						{
							ID = string.Empty,
							ConferenceId = conferenceId,
							Key = "State",
							DisplayName = conferenceMaster.IsInternational ? "State" : "省",
							Tip = conferenceMaster.IsInternational ? "State" : "省",
							IsRequired = false,
						});
						sqlResult.Insert(idx + 2, new ConferenceAttendenceForm
						{
							ID = string.Empty,
							ConferenceId = conferenceId,
							Key = "City",
							DisplayName = conferenceMaster.IsInternational ? "City" : "市",
							Tip = conferenceMaster.IsInternational ? "City" : "市",
							IsRequired = false,
						});
					}
				}

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					ConferenceId = x.ConferenceId,
					Key = x.Key,
					DisplayName = !string.IsNullOrEmpty(x.DisplayName) ? x.DisplayName : string.Empty,
					Tips = !string.IsNullOrEmpty(x.Tip) ? x.Tip : string.Empty,
					IsRequire = x.IsRequired,
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取参会注册发票信息
		public async Task<JsonCamelCaseResult> GetUserInvoiceMobile(string attendId)
		{
			var attendinfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);

			if (attendinfo != null)
			{
				var result = new
				{
					Id = attendinfo.ID,
					TaxNum = attendinfo.TaxNum,
					InvoiceTitle = attendinfo.InvoiceTitle,
					AddressAndTel = attendinfo.AddressAndTel,
					Bank = attendinfo.Bank,
					BankAccount = attendinfo.BankAccount
				};
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				var result = new { };
				return JsonCamelCase(new
				{
					data = result,
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//检查是否参会注册
		public async Task<JsonCamelCaseResult> CheckAttendMobile(string id, string conferenceId)
		{
			var sysUserMaster = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.ID == id);
			var attendenceId = "";
			if (sysUserMaster != null)
			{
				var conferenceAttendenceInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.Mail == sysUserMaster.Mail && x.ConferenceId == conferenceId);
				if (conferenceAttendenceInfo != null)
				{
					attendenceId = conferenceAttendenceInfo.ID;
				}
			}

			var result = new
			{
				attendenceId = attendenceId
			};

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//参会二维码
		public async Task<JsonCamelCaseResult> GetQrCodeMobile(string id)
		{
			var attendinfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == id);

			if (attendinfo != null)
			{

				var folder = ConstValues.SystemWeb + ConstValues.QRCodeImg.Replace(ConstValues.strWave, string.Empty);
				var conference = await DbContext.ConferenceMaster.FirstOrDefaultAsync(x => x.ID == attendinfo.ConferenceId);
				folder = folder + conference.ConferenceNickName + ConstValues.chrSlash;

				var result = new
				{
					QrCode = folder + Path.GetFileName(attendinfo.QRCode),
					Attendee = attendinfo.FullName,
					Mail = attendinfo.Mail
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//参会记录
		public async Task<JsonCamelCaseResult> GetConferencePersonalInfo(string id)
		{
			var personal = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == id);

			if (personal != null)
			{
				var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == personal.ConferenceId);

				var isBenefit = false;
				if (DateTime.Now >= conferenceMaster.BenefitStartDate && DateTime.Now <= conferenceMaster.BenefitEndDate)
				{
					isBenefit = true;
				}
				var payTypeId = DbContext.ConferencePaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.PaymentTypeId)?.PayId;
				//查询论文编号
				var essayList = await DbContext.ConferenceContributeInfo.AsNoTracking()
						.Where(x => personal.EssayId.Contains(x.ID.ToString()) &&
							x.EssayTitle != ConstValues.ChairmanReportCn &&
							x.EssayTitle != ConstValues.ChairmanReportEn)
						//.Select(x => x.EssayTitle)
						.ToListAsync();
				List<string> strList = new List<string>();
				essayList.ForEach(x =>
				{
					var reportType = DbContext.ReportMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.ReportId)?.ReportType;
					var rId = x.ID;
					var str = "";
					str += rId + ConstValues.strSpace + ConstValues.strLeftBracket + reportType + ConstValues.strRightBracket;
					strList.Add(str);
				});

				var essayArray = strList.ToArray();
				var essay = string.Join(ConstValues.chrSpace + ConstValues.strSemicolon + ConstValues.chrSpace, essayArray);

				//查询报告id
				var reportId = "";
				var reportList = await DbContext.ScheduleInfo.AsNoTracking().Where(x => personal.EssayId.Contains(x.ID.ToString())).ToListAsync();
				reportList.ForEach(x =>
				{
					if (reportId == "")
					{
						reportId += x.ID;
					}
					else
					{
						reportId += ConstValues.chrSpace + ConstValues.chrComma + ConstValues.chrSpace + x.ID;
					}
				});
				//查询费用明细
				var sql = from paymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.AttendenceId == id)
					  join attInfo in DbContext.ConferenceAttendenceInfo.AsNoTracking()
						  on paymentInfo.AttendenceId equals attInfo.ID
					  join conferenceMaster2 in DbContext.ConferenceMaster.AsNoTracking()
						  on attInfo.ConferenceId equals conferenceMaster2.ID
					  select new ProfilePayInfoModel
					  {
						  FeeType = paymentInfo.FeeType,
						  FeeId = paymentInfo.FeeId,
						  FeeName = string.Empty,
						  Count = paymentInfo.Count,
						  Currency = paymentInfo.Currency,
						  Fee = paymentInfo.Fee,
						  Discount = paymentInfo.Discount,
						  BenefitEndDate = conferenceMaster2.BenefitEndDate,
						  BenefitStartDate = conferenceMaster2.BenefitStartDate
					  };
				var sqlResult = await sql.ToListAsync();
				sqlResult.ForEach(x =>
				{
					if (x.FeeType == ConstValues.FeeType.餐费)
					{
						if (conferenceMaster.IsInternational)
						{
							x.FeeType = "Meal Fee";
						}
						else
						{
							x.FeeType = Resources.FeeMeal;
						}
						x.FeeName = DbContext.FeeMealMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
					}
					else if (x.FeeType == ConstValues.FeeType.参会费)
					{
						if (conferenceMaster.IsInternational)
						{
							x.FeeType = "Registration Fee";
						}
						else
						{
							x.FeeType = Resources.FeeAttend;
						}
						x.FeeName = DbContext.FeeAttendenceMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).RegisterType;
					}
					else if (x.FeeType == ConstValues.FeeType.版面费)
					{
						if (conferenceMaster.IsInternational)
						{
							x.FeeType = "Publication Fee";
						}
						else
						{
							x.FeeType = Resources.FeePage;
						}
						x.FeeName = DbContext.FeePageMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
					}
					else if (x.FeeType == ConstValues.FeeType.其他费用)
					{
						if (conferenceMaster.IsInternational)
						{
							x.FeeType = "Other Fee";
						}
						else
						{
							x.FeeType = Resources.FeeOther;
						}
						x.FeeName = DbContext.FeeOtherMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId).FeeName;
					}
					//else if (x.FeeType == ConstValues.FeeType.酒店费)
					//{
					//	x.FeeType = Resources.FeeHotel;

					//	var roomMaster = DbContext.RoomMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId);
					//	var hotelMaster = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(y => y.ID == roomMaster.HotelId);
					//	x.FeeName = hotelMaster.HotelName + ConstValues.strLeft + roomMaster.RoomType + ConstValues.strRight;
					//}
					else if (x.FeeType == ConstValues.FeeType.同期活动费)
					{
						if (conferenceMaster.IsInternational)
						{
							x.FeeType = "ConcurrentEvent Fee";
						}
						else
						{
							x.FeeType = Resources.ConferenceFeeEvent;
						}
						var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
						x.FeeName = DbContext.ConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
					}
				});
				List<string> feeDetailList = new List<string>();
				sqlResult.ForEach(x =>
				{
					var detailStr = "";
					detailStr += x.FeeType;
					detailStr += ConstValues.strSpace;
					detailStr += x.FeeName;
					detailStr += ConstValues.strSpace;
					detailStr += x.Currency;
					detailStr += ConstValues.chrSpace;
					if (isBenefit)
					{
						detailStr += x.Discount;
					}
					else
					{
						detailStr += x.Fee;
					}
					feeDetailList.Add(detailStr);
				});
				var feeDetail = string.Join("\n", feeDetailList);

				//查询支付时间
				var paymentRecord = await DbContext.ProfilePaymentRecord.AsNoTracking().FirstOrDefaultAsync(x => x.AttendenceId == id && x.FeeStatus == true);
				var paymentTime = "";
				if (paymentRecord != null)
				{
					paymentTime = conferenceMaster.IsInternational ? paymentRecord.CreateDate.Value.ToString("yyyy-MM-dd HH:mm") : paymentRecord.CreateDate.Value.ToString("MM/dd/yyyy HH:mm");
				}

				var result = new
				{
					attendid = personal.ID,
					fullname = personal.FullName,
					affiliation = personal.Affiliation,
					mail = personal.Mail,
					tele = personal.Mobile,
					country = conferenceMaster.IsInternational ?
							DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.NameEn :
							DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.Country)?.Name,
					essay = essay,
					address = personal.Address,
					zipCode = personal.ZipCode,
					fee = personal.Currency + ConstValues.strSpace + (isBenefit ? personal.Discount : personal.TotalFee).Value.ToString("N2"),
					payType = conferenceMaster.IsInternational ?
							DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentNameEn :
							DbContext.SysPaymentMaster.AsNoTracking().FirstOrDefault(x => x.ID == payTypeId)?.PaymentName,
					invoiceTitle = personal.InvoiceTitle,
					invoiceNum = personal.TaxNum,
					addressAndTel = personal.AddressAndTel,
					bank = personal.Bank,
					bankAccount = personal.BankAccount,
					bankAndAccount = personal.Bank + ConstValues.chrSpace + personal.BankAccount,
					invoiceId = personal.InvoiceNum,
					invoiceDetail = DbContext.ConferenceInvoiceMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.InvoiceId)?.InvoiceDetail,
					hotelId = DbContext.HotelMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.HotelId)?.HotelName,
					roomTypeId = DbContext.RoomMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.RoomTypeId)?.RoomType,
					arrivalDate = personal.ArrivalDate.HasValue ? (conferenceMaster.IsInternational ?
							personal.ArrivalDate.Value.ToString("MM/dd/yyyy") :
							personal.ArrivalDate.Value.ToString("yyyy-MM-dd")) : null,
					creator = personal.Creator,
					departuralDate = personal.DeparturalDate.HasValue ? (conferenceMaster.IsInternational ?
							personal.DeparturalDate.Value.ToString("MM/dd/yyyy") :
							personal.DeparturalDate.Value.ToString("yyyy-MM-dd")) : null,
					Id = personal.ID,
					arrivalFlight = personal.ArrivalFlight,
					departuralFlight = personal.DeparturalFlight,
					remark = personal.Remark,
					createDate = personal.CreateDate.HasValue ? (conferenceMaster.IsInternational ?
							personal.CreateDate.Value.ToString("MM/dd/yyyy") :
							personal.CreateDate.Value.ToString("yyyy-MM-dd")) : null,
					hotelRemark = personal.HotelRemark,
					attendenceIdentity = DbContext.AttendenceIdentityMaster.AsNoTracking().FirstOrDefault(x => x.ID == personal.AttendenceIdentityId)?.IdentityName,
					paymentHasPay = personal.ActuallyFee.HasValue ? (personal.Currency + ConstValues.strSpace + personal.ActuallyFee.Value.ToString("N2")) : string.Empty,
					hasPaid = personal.HasPaid == true ?
							(conferenceMaster.IsInternational ? "Has Paid" : Resources.HasPaid) :
							(conferenceMaster.IsInternational ? "Has Not Paid" : Resources.HasNotPaid),
					feeDetail = feeDetail,
					paymentTime = paymentTime,
					reportId = reportId,
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				var result = new { };
				return JsonCamelCase(new
				{
					data = result,
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//手机端参会注册android
		public async Task<JsonCamelCaseResult> MeetingAttendSubmitMobile(string conferenceId, string userName, string mailtxt, string lastNametxt, string firstNametxt, string fullNametxt, string jobtxt,
				string affiliationtxt, string departmenttxt, string addresstxt, string zipcodetxt, string teltxt, string mobiletxt, string idcardtxt, string invoiceTitletxt,
				string taxnumtxt, string addressAndTeltxt, string banktxt, string bankAccounttxt, string countrytxt, string statetxt, string citytxt, string attendenceIdentitytxt,
				string titletxt, string degreetxt, string attendenceFeetxt, string mealFeetxt, string pageFeetxt, string invoiceDetailtxt, string payTypetxt,
				string currencytxt, string gendertxt, string otherFeeList, string otherFeeCountList, string concurrentEventList, string concurrentEventCountList,
				string language, string isLogin, string fTopicList, 
				string customize1txt, string customize2txt, string customize3txt, string customize4txt, string customize5txt)
		{
			var userCurrency = currencytxt == "false" ? ConstValues.Currency.美元 : ConstValues.Currency.人民币;
			var userLanguage = language == "false" ? ConstValues.Language.En : ConstValues.Language.Cn;
			var conferenceAttendenceInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.Mail == mailtxt.Replace("~", " ") && x.ConferenceId == conferenceId);
			userName = userName.Replace("~", " ");
			if (conferenceAttendenceInfo != null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = language == "false" ? "The Mail has Existed!" : Resources.MsgMailExist
				}, JsonRequestBehavior.AllowGet);
			}
			else
			{
				var sysUserMaster = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mailtxt.Replace("~", " ") && x.Status == ConstValues.Status.正常);
				if (sysUserMaster == null)
				{
					var temp = mailtxt.Replace("~", " ").Split('@');
					if (temp.Length > 0)
					{
						var tempName = temp[0];
						var tmp = temp[1].Split('.');
						tempName = tempName + tmp[0];
						sysUserMaster = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.UserName == tempName && x.Status == ConstValues.Status.正常);
						if (sysUserMaster != null)
						{
							return JsonCamelCase(new
							{
								data = "",
								code = "0",
								msg = language == "false" ? "The Mail has Existed!" : Resources.MsgMailExist
							}, JsonRequestBehavior.AllowGet);
						}
					}
				}
			}

			var userInfo = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mailtxt.Replace("~", " ") && x.Status == ConstValues.Status.正常);
			if (userName == "")
			{
				if (userInfo != null)
				{
					userName = userInfo.UserName;
				}
				else
				{
					var temp = mailtxt.Replace("~", " ").Split('@');
					if (temp.Length > 0)
					{
						var tmp = temp[1].Split('.');
						userName = temp[0];
						userName = userName + tmp[0];
					}
				}
			}

			var titleId = "";
			var titleMaster = await DbContext.TitleMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.TitleName == titletxt.Replace("~", " ") && x.Status == ConstValues.Status.正常);
			if (titleMaster != null)
			{
				titleId = titleMaster.ID;
			}

			int? degreeId = 4;
			var degreeMaster = await DbContext.DegreeMaster.FirstOrDefaultAsync(x => x.DegreeName == degreetxt.Replace("~", " ") || x.DegreeNameEn == degreetxt.Replace("~", " "));
			if (degreeMaster != null)
			{
				degreeId = degreeMaster.ID;
			}

			var identityId = "";
			var attendenceIdentityMaster = await DbContext.AttendenceIdentityMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.IdentityName == attendenceIdentitytxt.Replace("~", " ") && x.Status == ConstValues.Status.正常);
			if (attendenceIdentityMaster != null)
			{
				identityId = attendenceIdentityMaster.ID;
			}

			var invoiceId = "";
			var invoiceMaster = await DbContext.ConferenceInvoiceMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.InvoiceDetail == invoiceDetailtxt.Replace("~", " ") && x.Status == ConstValues.Status.正常);
			if (invoiceMaster != null)
			{
				invoiceId = invoiceMaster.ID;
			}

			var payTypeId = "";
			var SysPaymentMaster = await DbContext.SysPaymentMaster.FirstOrDefaultAsync(x => (x.PaymentName == payTypetxt.Replace("~", " ") || x.PaymentNameEn == payTypetxt.Replace("~", " ")) && x.Status == ConstValues.Status.正常);
			if (SysPaymentMaster != null)
			{
				var conferencePaymentMaster = await DbContext.ConferencePaymentMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.PayId == SysPaymentMaster.ID && x.Status == ConstValues.Status.正常);
				if (conferencePaymentMaster != null)
				{
					payTypeId = conferencePaymentMaster.ID;
				}
			}

			int countryVal = 0;
			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == countrytxt.Replace("~", " ") || x.NameEn == countrytxt.Replace("~", " "));
			if (country != null)
			{
				countryVal = country.ID;
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				#region ConferenceAttendenceInfo
				var result = new ConferenceAttendenceInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.ConferenceAttendenceInfo),
					ConferenceId = conferenceId,
					Mail = mailtxt.Replace("~", " "),
					FamilyName = lastNametxt?.Replace("~", " "),
					FirstName = firstNametxt?.Replace("~", " "),
					FullName = string.IsNullOrEmpty(fullNametxt?.Replace("~", " ")) ?
							Utility.SetFullName(lastNametxt?.Replace("~", " "), firstNametxt?.Replace("~", " "), userLanguage) :
							fullNametxt?.Replace("~", " "),
					Gender = gendertxt == "true" ? true : false,
					Title = titleId,
					Job = jobtxt.Replace("~", " "),
					Affiliation = affiliationtxt.Replace("~", " "),
					Department = departmenttxt.Replace("~", " "),
					StateStr = statetxt.Replace("~", " "),
					CityStr = citytxt.Replace("~", " "),
					Address = addresstxt.Replace("~", " "),
					ZipCode = zipcodetxt.Replace("~", " "),
					Telephone = teltxt.Replace("~", " "),
					Mobile = mobiletxt.Replace("~", " "),
					CardId = idcardtxt.Replace("~", " "),
					AttendenceIdentityId = identityId,
					InvoiceTitle = invoiceTitletxt.Replace("~", " "),
					TaxNum = taxnumtxt.Replace("~", " "),
					AddressAndTel = addressAndTeltxt.Replace("~", " "),
					Bank = banktxt.Replace("~", " "),
					BankAccount = bankAccounttxt.Replace("~", " "),
					InvoiceId = invoiceId,
					FavouriteTopicId = string.IsNullOrEmpty(fTopicList) ? string.Empty : fTopicList,
					Customize1 = customize1txt.Replace("~", " "),
					Customize2 = customize2txt.Replace("~", " "),
					Customize3 = customize3txt.Replace("~", " "),
					Customize4 = customize4txt.Replace("~", " "),
					Customize5 = customize5txt.Replace("~", " "),
					PaymentTypeId = payTypeId,
					HasVisa = false,
					HasHotel = false,
					HasMeal = false,
					HasPage = false,
					HasContributed = false,
					HasPaid = false,
					HasArrived = false,
					HasPrinted = false,
					HasDinner = false,
					HasInvoiced = false,
					HasSendMail = false,
					HasSendPaid = false,
					IsRefund = false,
					TransferEvidenceId = string.Empty,
					TotalFee = 0.00,
					Discount = 0.00,
					Currency = !string.IsNullOrEmpty(userCurrency) ? userCurrency : ConstValues.Currency.人民币,
					Sort = ConstValues.DefaultSort,
					Creator = userName,
					//CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};
				#endregion

				if (degreeId != 0)
				{
					result.Degree = degreeId;
				}
				if (countryVal != 0)
				{
					result.Country = countryVal;
				}

				#region QRCode
				var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == result.ConferenceId);

				result.QRCode = Utility.CreateQRCode(result.ID,
						Server.MapPath(Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName)),
						Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName));
				#endregion

				#region ProfilePaymentInfo
				double totalFee = 0;
				double totalDiscount = 0;
				var currency = string.Empty;

				var pageFeeId = "";
				var pageFeeName = pageFeetxt.Replace("~", " ").Split(':');
				if (pageFeeName.Length > 0)
				{
					string name = pageFeeName[0];
					var feePageMaster = await DbContext.FeePageMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.FeeName == name
									&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feePageMaster != null)
					{
						pageFeeId = feePageMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(pageFeeId))
				{
					var feeMaster = DbContext.FeePageMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == pageFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.版面费,
							FeeId = pageFeeId,
							Count = 1,
							Fee = feeMaster.Price.Value,
							Discount = feeMaster.Price.Value,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += feeMaster.Price.Value;
						totalDiscount += feeMaster.Price.Value;
						currency = feeMaster.Currency;
						result.HasPage = true;
					}
				}

				var attendFeeId = "";
				var attendFeeName = attendenceFeetxt.Replace("~", " ").Split(':');
				if (attendFeeName.Length > 0)
				{
					string name = attendFeeName[0];
					var feeAttendenceMaster = await DbContext.FeeAttendenceMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.RegisterType == name
											&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feeAttendenceMaster != null)
					{
						attendFeeId = feeAttendenceMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(attendFeeId))
				{
					var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == attendFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						double originFee = feeMaster.Price.Value;
						double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.参会费,
							FeeId = attendFeeId,
							Count = 1,
							Fee = originFee,
							Discount = discountFee,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += originFee;
						totalDiscount += discountFee;
						currency = feeMaster.Currency;
					}
				}

				var mealFeeId = "";
				var mealFeeName = mealFeetxt.Replace("~", " ").Split(':');
				if (mealFeeName.Length > 0)
				{
					string name = mealFeeName[0];
					var feeMealMaster = await DbContext.FeeMealMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.FeeName == name
										&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feeMealMaster != null)
					{
						mealFeeId = feeMealMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(mealFeeId))
				{
					var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == mealFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.餐费,
							FeeId = mealFeeId,
							Count = 1,
							Fee = feeMaster.Price.Value,
							Discount = feeMaster.Price.Value,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += feeMaster.Price.Value;
						totalDiscount += feeMaster.Price.Value;
						currency = feeMaster.Currency;
						result.HasMeal = true;
					}
				}

				if (!string.IsNullOrEmpty(otherFeeList) && !string.IsNullOrEmpty(otherFeeCountList))
				{
					var otherFeeListNew = otherFeeList.Split(',');
					var otherFeeCountListNew = otherFeeCountList.Split(',');
					for (var index = 0; index < otherFeeListNew.Length; index++)
					{
						string tmp = otherFeeListNew[index];
						int count = Convert.ToInt32(otherFeeCountListNew[index]);

						var feeMaster = DbContext.FeeOtherMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == tmp);

						if (feeMaster != null && count != 0)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = userName,
								AttendenceId = result.ID,
								FeeType = ConstValues.FeeType.其他费用,
								FeeId = tmp,
								Count = count,
								Fee = feeMaster.Price.Value * count,
								Discount = feeMaster.Price.Value * count,
								Currency = feeMaster.Currency,
								Creator = userName,
								//CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							totalFee += feeMaster.Price.Value * count;
							totalDiscount += feeMaster.Price.Value * count;
							currency = feeMaster.Currency;
						}
					}
				}
				//同期活动费用
				if (!string.IsNullOrEmpty(concurrentEventList) && !string.IsNullOrEmpty(concurrentEventCountList))
				{
					var concurrentEventListNew = concurrentEventList.Split(',');
					var concurrentEventCountNew = concurrentEventCountList.Split(',');
					for (var index = 0; index < concurrentEventListNew.Length; index++)
					{
						string tmp = concurrentEventListNew[index];
						int count = int.Parse(concurrentEventCountNew[index]);

						var feeMaster = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(x => x.ConcurrentEventId == tmp && x.Status == ConstValues.Status.正常
									&& (x.AttendenceIdentityId == identityId || x.AttendenceIdentityId == ConstValues.ApplicableForAll)
									&& x.Currency == userCurrency);

						if (feeMaster != null && count != 0)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = userName,
								AttendenceId = result.ID,
								FeeType = ConstValues.FeeType.同期活动费,
								FeeId = feeMaster.ID,
								Count = count,
								Fee = feeMaster.Price.Value * count,
								Discount = feeMaster.Price.Value * count,
								Currency = feeMaster.Currency,
								Creator = userName,
								//CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							totalFee += feeMaster.Price.Value * count;
							totalDiscount += feeMaster.Price.Value * count;
							currency = feeMaster.Currency;
						}
					}
				}

				//if (!string.IsNullOrEmpty(infoTmp.HotelId) && !string.IsNullOrEmpty(infoTmp.RoomTypeId))
				//{
				//	var roomMaster = DbContext.RoomMaster
				//			.FirstOrDefault(x => x.ID == infoTmp.RoomTypeId);

				//	if (roomMaster != null && roomMaster.Price1.HasValue)
				//	{
				//		int count = infoTmp.CheckinDaysCount.HasValue ? infoTmp.CheckinDaysCount.Value : 1;
				//		double originFee = roomMaster.Price1.Value;
				//		double discountFee = roomMaster.Price2.HasValue ? roomMaster.Price2.Value : roomMaster.Price1.Value;

				//		var profilePaymentInfo = new ProfilePaymentInfo
				//		{
				//			ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
				//			UserName = LoginUser.UserName,
				//			AttendenceId = code,
				//			FeeType = ConstValues.FeeType.酒店费,
				//			FeeId = infoTmp.RoomTypeId,
				//			Count = count * infoTmp.BedCount.Value,
				//			Fee = originFee * count * infoTmp.BedCount.Value,
				//			Discount = discountFee * count * infoTmp.BedCount.Value,
				//			Currency = roomMaster.Currency,
				//			Creator = LoginUser.UserName,
				//			CreateIP = LoginUser.IP,
				//			CreateDate = DateTime.Now
				//		};

				//		DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

				//		totalFee += originFee * count * infoTmp.BedCount.Value;
				//		totalDiscount += discountFee * count * infoTmp.BedCount.Value;
				//		currency = roomMaster.Currency;
				//		result.HasHotel = true;
				//	}
				//}

				if (totalFee != 0)
				{
					result.TotalFee = totalFee;
				}
				if (totalDiscount != 0)
				{
					result.Discount = totalDiscount;
				}
				if (!string.IsNullOrEmpty(currency))
				{
					result.Currency = currency;
				}
				#endregion

				DbContext.ConferenceAttendenceInfo.Add(result);

				#region SysUserMaster
				var isNewUser = false;
				var temp = mailtxt.Replace("~", " ").Split('@');
				if (temp.Length > 0)
				{
					var tmp = temp[1].Split('.');
					userName = temp[0];
					userName = userName + tmp[0];
				}
				if (userInfo != null)
				{
					userInfo.InvoiceTitle = invoiceTitletxt.Replace("~", " ");
					userInfo.TaxNum = taxnumtxt.Replace("~", " ");
					userInfo.AddressAndTel = addressAndTeltxt.Replace("~", " ");
					userInfo.Bank = banktxt.Replace("~", " ");
					userInfo.BankAccount = bankAccounttxt.Replace("~", " ");
				}
				else
				{
					if (isLogin == "false")
					{
						isNewUser = true;
						userInfo = new SysUserMaster
						{
							ID = Utility.GetTableId(ConstValues.TableName.SysUserMaster),
							UserName = userName,
							Mail = mailtxt.Replace("~", " "),
							Call = gendertxt == "true" ? ConstValues.RegisterMobile.MR : ConstValues.RegisterMobile.MS,
							FamilyName = lastNametxt.Replace("~", " "),
							FirstName = firstNametxt.Replace("~", " "),
							FullName = string.IsNullOrEmpty(fullNametxt?.Replace("~", " ")) ?
									Utility.SetFullName(lastNametxt?.Replace("~", " "), firstNametxt?.Replace("~", " "), userLanguage) :
									fullNametxt?.Replace("~", " "),
							Gender = gendertxt == "true" ? true : false,
							Password = StringExtension.Encrypt(userName),
							//Birthday = model.Birthday,
							Degree = degreeId,
							//HeadImg = model.HeadImgFilePath?.Trim(),
							Affiliation = affiliationtxt.Replace("~", " "),
							StateStr = statetxt.Replace("~", " "),
							CityStr = citytxt.Replace("~", " "),
							Address = addresstxt.Replace("~", " "),
							ZipCode = zipcodetxt.Replace("~", " "),
							Telephone = teltxt.Replace("~", " "),
							Department = departmenttxt.Replace("~", " "),
							Career = ConstValues.RegisterMobile.Career,
							OcisCode = ConstValues.RegisterMobile.OCIS,
							Status = ConstValues.Status.正常,
							Sort = ConstValues.DefaultSort,
							IsLocked = false,
							PasswordFailed = ConstValues.intZero,
							Language = language == "false" ? ConstValues.Language.En : ConstValues.Language.Cn,
							Mobile = mobiletxt.Replace("~", " "),
							InvoiceTitle = invoiceTitletxt.Replace("~", " "),
							TaxNum = taxnumtxt.Replace("~", " "),
							AddressAndTel = addressAndTeltxt.Replace("~", " "),
							Bank = banktxt.Replace("~", " "),
							BankAccount = bankAccounttxt.Replace("~", " "),
							Creator = userName,
							CreateDate = DateTime.Now,
							HasSend = false
						};
						if (degreeId != 0)
						{
							userInfo.Degree = degreeId;
						}
						if (countryVal != 0)
						{
							userInfo.Country = countryVal;
						}

						DbContext.SysUserMaster.Add(userInfo);

						var smtpServer = ConstValues.SmtpServer;
						var mailAddress = ConstValues.MailAddress;
						var password = ConstValues.MailPassword;

						var mailServer = await DbContext.SysMailServerMaster.AsNoTracking()
								.OrderBy(x => x.Sort)
								.ThenByDescending(x => x.UpdateDate)
								.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常);

						if (mailServer != null)
						{
							smtpServer = mailServer.MailServer;
							mailAddress = mailServer.Mail;
							password = mailServer.Password;
						}

						MailSender sender = new MailSender(smtpServer);
						MailAddress from = new MailAddress(mailAddress);
						MailAddress to = new MailAddress(result.Mail);

						MailMessage message = Utility.GetMailContent(new MailModel
						{
							MailRemark = ConstValues.MailSubject.系统注册,
							Language = language,
							ActiveUrl = ConstValues.SystemWeb + "/Account/Activate/" + userInfo.ID,
							ActiveUrlTxt = ConstValues.SystemWeb + "/Account/Activate/" + userInfo.ID,
						});
						message.To.Add(to);

						var mailTask = Task.Run(() =>
						{
							sender.SendMail(from, message, password);
						});
					}
				}
				#endregion

				await DbContext.SaveChangesAsync();
				transaction.Commit();

				#region SendMail
				var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.MailType == ConstValues.MailType.注册服务邮箱 &&
							x.ConferenceId == conferenceId);

				if (conferenceMailServerMaster == null)
				{
					conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
								x.MailType == ConstValues.MailType.会议邮箱 &&
								x.ConferenceId == conferenceId);
				}

				if (conferenceMailServerMaster != null)
				{
					var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.ID == conferenceId);

					MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
					MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
					MailAddress to = new MailAddress(result.Mail);

					MailMessage message = Utility.GetMailContent(new MailModel
					{
						MailRemark = ConstValues.MailSubject.会议注册,
						Language = language,
						UserName = result.FullName,
						ConferenceId = conferenceMaster.ID,
						ConferenceName = conferenceMaster.ConferenceName,
						ConferenceNickName = conferenceMaster.ConferenceNickName,
						ConferenceUrl = !string.IsNullOrEmpty(conferenceMaster.HomePageUrl) ? conferenceMaster.HomePageUrl :
							ConstValues.SystemWeb + "/MeetingMain/Index/" + conferenceMaster.ConferenceNickName,
						AttendenceId = result.ID
					});
					message.To.Add(to);
					//message.Attachments.Add(new Attachment(Server.MapPath(result.QRCode)));

					if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
					{
						foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
						{
							if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
							{
								message.Bcc.Add(new MailAddress(cc.Trim()));
							}
						}
					}

					var mailTask = Task.Run(() =>
					{
						sender.SendMail(from, message, conferenceMailServerMaster.Password);
					});
				}
				#endregion

				var userBox = new
				{
					isNewUser = isNewUser,
					mail = mailtxt.Replace("~", " "),
					userName = userName,
					password = userName
				};

				return JsonCamelCase(new
				{
					data = userBox,
					code = "1",
					msg = "success"

				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//手机端参会注册IOS
		public async Task<JsonCamelCaseResult> MeetingAttendSubmitIOS(MeetingAttendIOSModel model)
		{
			//从model中接收数据
			var conferenceId = model.conferenceId;
			var userName = model.userName;
			var mailtxt = model.mailtxt;
			var lastNametxt = model.lastNametxt;
			var firstNametxt = model.firstNametxt;
			var fullNametxt = model.fullNametxt;
			var gendertxt = model.gendertxt;
			var titletxt = model.titletxt;
			var degreetxt = model.degreetxt;
			var jobtxt = model.jobtxt;
			var affiliationtxt = model.affiliationtxt;
			var departmenttxt = model.departmenttxt;
			var countrytxt = model.countrytxt;
			var statetxt = model.statetxt;
			var citytxt = model.citytxt;
			var addresstxt = model.addresstxt;
			var zipcodetxt = model.zipcodetxt;
			var teltxt = model.teltxt;
			var mobiletxt = model.mobiletxt;
			var idcardtxt = model.idcardtxt;

			var attendenceIdentitytxt = model.attendenceIdentitytxt;
			var attendenceFeetxt = model.attendenceFeetxt;
			var pageFeetxt = model.pageFeetxt;
			var mealFeetxt = model.mealFeetxt;
			var otherFeeList = model.otherFeeList;
			var otherFeeCountList = model.otherFeeCountList;
			var invoiceTitletxt = model.invoiceTitletxt;
			var taxnumtxt = model.taxnumtxt;
			var addressAndTeltxt = model.addressAndTeltxt;
			var banktxt = model.banktxt;
			var bankAccounttxt = model.bankAccounttxt;
			var invoiceDetailtxt = model.invoiceDetailtxt;
			var fTopicList = model.fTopicList;
			var customize1txt = model.customize1txt;
			var customize2txt = model.customize2txt;
			var customize3txt = model.customize3txt;
			var customize4txt = model.customize4txt;
			var customize5txt = model.customize5txt;
			var concurrentEventList = model.concurrentEventList;
			var concurrentEventCountList = model.concurrentEventCountList;
			var payTypetxt = model.payTypetxt;
			var currencytxt = model.currencytxt;
			var language = model.language;
			var isLogin = model.isLogin;

			//此后的代码和前面android的一样
			var userCurrency = currencytxt == "false" ? ConstValues.Currency.美元 : ConstValues.Currency.人民币;
			var userLanguage = language == "false" ? ConstValues.Language.En : ConstValues.Language.Cn;
			var conferenceAttendenceInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.Mail == mailtxt && x.ConferenceId == conferenceId);

			if (conferenceAttendenceInfo != null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = language == "false" ? "The Mail has Existed!" : Resources.MsgMailExist
				}, JsonRequestBehavior.AllowGet);
			}
			else
			{
				var sysUserMaster = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mailtxt && x.Status == ConstValues.Status.正常);
				if (sysUserMaster == null)
				{
					var temp = mailtxt.Split('@');
					if (temp.Length > 0)
					{
						var tempName = temp[0];
						var tmp = temp[1].Split('.');
						tempName = tempName + tmp[0];
						sysUserMaster = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.UserName == tempName && x.Status == ConstValues.Status.正常);
						if (sysUserMaster != null)
						{
							return JsonCamelCase(new
							{
								data = "",
								code = "0",
								msg = language == "false" ? "The Mail has Existed!" : Resources.MsgMailExist
							}, JsonRequestBehavior.AllowGet);
						}
					}
				}
			}

			var userInfo = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mailtxt && x.Status == ConstValues.Status.正常);
			if (string.IsNullOrEmpty(userName))
			{
				if (userInfo != null)
				{
					userName = userInfo.UserName;
				}
				else
				{
					var temp = mailtxt.Split('@');
					if (temp.Length > 0)
					{
						var tmp = temp[1].Split('.');
						userName = temp[0];
						userName = userName + tmp[0];
					}
				}
			}

			var titleId = "";
			var titleMaster = await DbContext.TitleMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.TitleName == titletxt && x.Status == ConstValues.Status.正常);
			if (titleMaster != null)
			{
				titleId = titleMaster.ID;
			}

			int? degreeId = 4;
			var degreeMaster = await DbContext.DegreeMaster.FirstOrDefaultAsync(x => x.DegreeName == degreetxt || x.DegreeNameEn == degreetxt);
			if (degreeMaster != null)
			{
				degreeId = degreeMaster.ID;
			}

			var identityId = "";
			var attendenceIdentityMaster = await DbContext.AttendenceIdentityMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.IdentityName == attendenceIdentitytxt && x.Status == ConstValues.Status.正常);
			if (attendenceIdentityMaster != null)
			{
				identityId = attendenceIdentityMaster.ID;
			}

			var invoiceId = "";
			var invoiceMaster = await DbContext.ConferenceInvoiceMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.InvoiceDetail == invoiceDetailtxt && x.Status == ConstValues.Status.正常);
			if (invoiceMaster != null)
			{
				invoiceId = invoiceMaster.ID;
			}

			var payTypeId = "";
			var SysPaymentMaster = await DbContext.SysPaymentMaster.FirstOrDefaultAsync(x => (x.PaymentName == payTypetxt || x.PaymentNameEn == payTypetxt) && x.Status == ConstValues.Status.正常);
			if (SysPaymentMaster != null)
			{
				var conferencePaymentMaster = await DbContext.ConferencePaymentMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.PayId == SysPaymentMaster.ID && x.Status == ConstValues.Status.正常);
				if (conferencePaymentMaster != null)
				{
					payTypeId = conferencePaymentMaster.ID;
				}
			}

			int countryVal = 0;
			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == countrytxt || x.NameEn == countrytxt);
			if (country != null)
			{
				countryVal = country.ID;
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				#region ConferenceAttendenceInfo
				var result = new ConferenceAttendenceInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.ConferenceAttendenceInfo),
					ConferenceId = conferenceId,
					Mail = mailtxt?.Trim(),
					FamilyName = lastNametxt?.Trim(),
					FirstName = firstNametxt?.Trim(),
					FullName = string.IsNullOrEmpty(fullNametxt?.Trim()) ?
							Utility.SetFullName(lastNametxt?.Trim(), firstNametxt?.Trim(), userLanguage) :
							fullNametxt?.Trim(),
					Gender = gendertxt == "true" ? true : false,
					Title = titleId,
					Job = jobtxt?.Trim(),
					Affiliation = affiliationtxt?.Trim(),
					Department = departmenttxt?.Trim(),
					StateStr = statetxt?.Trim(),
					CityStr = citytxt?.Trim(),
					Address = addresstxt?.Trim(),
					ZipCode = zipcodetxt?.Trim(),
					Telephone = teltxt?.Trim(),
					Mobile = mobiletxt?.Trim(),
					CardId = idcardtxt?.Trim(),
					AttendenceIdentityId = identityId,
					InvoiceTitle = invoiceTitletxt?.Trim(),
					TaxNum = taxnumtxt?.Trim(),
					AddressAndTel = addressAndTeltxt?.Trim(),
					Bank = banktxt?.Trim(),
					BankAccount = bankAccounttxt?.Trim(),
					InvoiceId = invoiceId,
					FavouriteTopicId = string.IsNullOrEmpty(fTopicList) ? string.Empty : fTopicList,
					Customize1 = customize1txt?.Trim(),
					Customize2 = customize2txt?.Trim(),
					Customize3 = customize3txt?.Trim(),
					Customize4 = customize4txt?.Trim(),
					Customize5 = customize5txt?.Trim(),
					PaymentTypeId = payTypeId,
					HasVisa = false,
					HasHotel = false,
					HasMeal = false,
					HasPage = false,
					HasContributed = false,
					HasPaid = false,
					HasArrived = false,
					HasPrinted = false,
					HasDinner = false,
					HasInvoiced = false,
					HasSendMail = false,
					HasSendPaid = false,
					IsRefund = false,
					TransferEvidenceId = string.Empty,
					TotalFee = 0.00,
					Discount = 0.00,
					Currency = !string.IsNullOrEmpty(userCurrency) ? userCurrency : ConstValues.Currency.人民币,
					Sort = ConstValues.DefaultSort,
					Creator = userName,
					//CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};
				#endregion

				if (degreeId != 0)
				{
					result.Degree = degreeId;
				}
				if (countryVal != 0)
				{
					result.Country = countryVal;
				}

				#region QRCode
				var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == result.ConferenceId);

				result.QRCode = Utility.CreateQRCode(result.ID,
						Server.MapPath(Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName)),
						Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName));
				#endregion

				#region ProfilePaymentInfo
				double totalFee = 0;
				double totalDiscount = 0;
				var currency = string.Empty;

				var pageFeeId = "";
				var pageFeeName = string.IsNullOrEmpty(pageFeetxt) ? string.Empty.Split(':') : pageFeetxt.Split(':');
				if (pageFeeName.Length > 0)
				{
					string name = pageFeeName[0];
					var feePageMaster = await DbContext.FeePageMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.FeeName == name
									&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feePageMaster != null)
					{
						pageFeeId = feePageMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(pageFeeId))
				{
					var feeMaster = DbContext.FeePageMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == pageFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.版面费,
							FeeId = pageFeeId,
							Count = 1,
							Fee = feeMaster.Price.Value,
							Discount = feeMaster.Price.Value,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += feeMaster.Price.Value;
						totalDiscount += feeMaster.Price.Value;
						currency = feeMaster.Currency;
						result.HasPage = true;
					}
				}

				var attendFeeId = "";
				var attendFeeName = string.IsNullOrEmpty(attendenceFeetxt) ? string.Empty.Split(':') : attendenceFeetxt.Split(':');
				if (attendFeeName.Length > 0)
				{
					string name = attendFeeName[0];
					var feeAttendenceMaster = await DbContext.FeeAttendenceMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.RegisterType == name
											&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feeAttendenceMaster != null)
					{
						attendFeeId = feeAttendenceMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(attendFeeId))
				{
					var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == attendFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						double originFee = feeMaster.Price.Value;
						double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.参会费,
							FeeId = attendFeeId,
							Count = 1,
							Fee = originFee,
							Discount = discountFee,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += originFee;
						totalDiscount += discountFee;
						currency = feeMaster.Currency;
					}
				}

				var mealFeeId = "";
				var mealFeeName = string.IsNullOrEmpty(mealFeetxt) ? string.Empty.Split(':') : mealFeetxt.Split(':');
				if (mealFeeName.Length > 0)
				{
					string name = mealFeeName[0];
					var feeMealMaster = await DbContext.FeeMealMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.FeeName == name
										&& x.Status == ConstValues.Status.正常 && x.Currency == userCurrency);
					if (feeMealMaster != null)
					{
						mealFeeId = feeMealMaster.ID;
					}
				}
				if (!string.IsNullOrEmpty(mealFeeId))
				{
					var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
							.FirstOrDefault(x => x.ID == mealFeeId);
					if (feeMaster != null && feeMaster.Price.HasValue)
					{
						var profilePaymentInfo = new ProfilePaymentInfo
						{
							ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
							UserName = userName,
							AttendenceId = result.ID,
							FeeType = ConstValues.FeeType.餐费,
							FeeId = mealFeeId,
							Count = 1,
							Fee = feeMaster.Price.Value,
							Discount = feeMaster.Price.Value,
							Currency = feeMaster.Currency,
							Creator = userName,
							//CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};

						DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

						totalFee += feeMaster.Price.Value;
						totalDiscount += feeMaster.Price.Value;
						currency = feeMaster.Currency;
						result.HasMeal = true;
					}
				}

				if (!string.IsNullOrEmpty(otherFeeList) && !string.IsNullOrEmpty(otherFeeCountList))
				{
					var otherFeeListNew = otherFeeList.Split(',');
					var otherFeeCountListNew = otherFeeCountList.Split(',');
					for (var index = 0; index < otherFeeListNew.Length; index++)
					{
						string tmp = otherFeeListNew[index];
						int count = Convert.ToInt32(otherFeeCountListNew[index]);

						var feeMaster = DbContext.FeeOtherMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == tmp);

						if (feeMaster != null && count != 0)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = userName,
								AttendenceId = result.ID,
								FeeType = ConstValues.FeeType.其他费用,
								FeeId = tmp,
								Count = count,
								Fee = feeMaster.Price.Value * count,
								Discount = feeMaster.Price.Value * count,
								Currency = feeMaster.Currency,
								Creator = userName,
								//CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							totalFee += feeMaster.Price.Value * count;
							totalDiscount += feeMaster.Price.Value * count;
							currency = feeMaster.Currency;
						}
					}
				}
				//同期活动费用
				if (!string.IsNullOrEmpty(concurrentEventList) && !string.IsNullOrEmpty(concurrentEventCountList))
				{
					var concurrentEventListNew = concurrentEventList.Split(',');
					var concurrentEventCountNew = concurrentEventCountList.Split(',');
					for (var index = 0; index < concurrentEventListNew.Length; index++)
					{
						string tmp = concurrentEventListNew[index];
						int count = int.Parse(concurrentEventCountNew[index]);

						var feeMaster = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(x => x.ConcurrentEventId == tmp && x.Status == ConstValues.Status.正常
									&& (x.AttendenceIdentityId == identityId || x.AttendenceIdentityId == ConstValues.ApplicableForAll)
									&& x.Currency == userCurrency);

						if (feeMaster != null && count != 0)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = userName,
								AttendenceId = result.ID,
								FeeType = ConstValues.FeeType.同期活动费,
								FeeId = feeMaster.ID,
								Count = count,
								Fee = feeMaster.Price.Value * count,
								Discount = feeMaster.Price.Value * count,
								Currency = feeMaster.Currency,
								Creator = userName,
								//CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							totalFee += feeMaster.Price.Value * count;
							totalDiscount += feeMaster.Price.Value * count;
							currency = feeMaster.Currency;
						}
					}
				}

				if (totalFee != 0)
				{
					result.TotalFee = totalFee;
				}
				if (totalDiscount != 0)
				{
					result.Discount = totalDiscount;
				}
				if (!string.IsNullOrEmpty(currency))
				{
					result.Currency = currency;
				}
				#endregion

				DbContext.ConferenceAttendenceInfo.Add(result);

				#region SysUserMaster
				var isNewUser = false;
				var temp = mailtxt.Split('@');
				if (temp.Length > 0)
				{
					var tmp = temp[1].Split('.');
					userName = temp[0];
					userName = userName + tmp[0];
				}
				if (userInfo != null)
				{
					userInfo.InvoiceTitle = invoiceTitletxt;
					userInfo.TaxNum = taxnumtxt;
					userInfo.AddressAndTel = addressAndTeltxt;
					userInfo.Bank = banktxt;
					userInfo.BankAccount = bankAccounttxt;
				}
				else
				{
					if (isLogin == "false")
					{
						isNewUser = true;
						userInfo = new SysUserMaster
						{
							ID = Utility.GetTableId(ConstValues.TableName.SysUserMaster),
							UserName = userName,
							Mail = mailtxt,
							Call = gendertxt == "true" ? ConstValues.RegisterMobile.MR : ConstValues.RegisterMobile.MS,
							FamilyName = lastNametxt,
							FirstName = firstNametxt,
							FullName = string.IsNullOrEmpty(fullNametxt?.Trim()) ?
									Utility.SetFullName(lastNametxt?.Trim(), firstNametxt?.Trim(), userLanguage) :
									fullNametxt?.Trim(),
							Gender = gendertxt == "true" ? true : false,
							Password = StringExtension.Encrypt(userName),
							//Birthday = model.Birthday,
							Degree = degreeId,
							//HeadImg = model.HeadImgFilePath?.Trim(),
							Affiliation = affiliationtxt,

							Address = addresstxt,
							ZipCode = zipcodetxt,
							Telephone = teltxt,
							Department = departmenttxt,
							StateStr = statetxt,
							CityStr = citytxt,
							Career = ConstValues.RegisterMobile.Career,
							OcisCode = ConstValues.RegisterMobile.OCIS,
							Status = ConstValues.Status.正常,
							Sort = ConstValues.DefaultSort,
							IsLocked = false,
							PasswordFailed = ConstValues.intZero,
							Language = language == "false" ? ConstValues.Language.En : ConstValues.Language.Cn,
							Mobile = mobiletxt,
							InvoiceTitle = invoiceTitletxt,
							TaxNum = taxnumtxt,
							AddressAndTel = addressAndTeltxt,
							Bank = banktxt,
							BankAccount = bankAccounttxt,
							Creator = userName,
							CreateDate = DateTime.Now,
							HasSend = false
						};
						if (degreeId != 0)
						{
							userInfo.Degree = degreeId;
						}
						if (countryVal != 0)
						{
							userInfo.Country = countryVal;
						}

						DbContext.SysUserMaster.Add(userInfo);

						var smtpServer = ConstValues.SmtpServer;
						var mailAddress = ConstValues.MailAddress;
						var password = ConstValues.MailPassword;

						var mailServer = await DbContext.SysMailServerMaster.AsNoTracking()
								.OrderBy(x => x.Sort)
								.ThenByDescending(x => x.UpdateDate)
								.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常);

						if (mailServer != null)
						{
							smtpServer = mailServer.MailServer;
							mailAddress = mailServer.Mail;
							password = mailServer.Password;
						}

						MailSender sender = new MailSender(smtpServer);
						MailAddress from = new MailAddress(mailAddress);
						MailAddress to = new MailAddress(result.Mail);

						MailMessage message = Utility.GetMailContent(new MailModel
						{
							MailRemark = ConstValues.MailSubject.系统注册,
							Language = language,
							ActiveUrl = ConstValues.SystemWeb + "/Account/Activate/" + userInfo.ID,
							ActiveUrlTxt = ConstValues.SystemWeb + "/Account/Activate/" + userInfo.ID,
						});
						message.To.Add(to);

						var mailTask = Task.Run(() =>
						{
							sender.SendMail(from, message, password);
						});
					}
				}
				#endregion

				await DbContext.SaveChangesAsync();
				transaction.Commit();

				#region SendMail
				var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.MailType == ConstValues.MailType.注册服务邮箱 &&
							x.ConferenceId == conferenceId);

				if (conferenceMailServerMaster == null)
				{
					conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
								x.MailType == ConstValues.MailType.会议邮箱 &&
								x.ConferenceId == conferenceId);
				}

				if (conferenceMailServerMaster != null)
				{
					var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.ID == conferenceId);

					MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
					MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
					MailAddress to = new MailAddress(result.Mail);

					MailMessage message = Utility.GetMailContent(new MailModel
					{
						MailRemark = ConstValues.MailSubject.会议注册,
						Language = language,
						UserName = result.FullName,
						ConferenceId = conferenceMaster.ID,
						ConferenceName = conferenceMaster.ConferenceName,
						ConferenceNickName = conferenceMaster.ConferenceNickName,
						ConferenceUrl = !string.IsNullOrEmpty(conferenceMaster.HomePageUrl) ? conferenceMaster.HomePageUrl :
							ConstValues.SystemWeb + "/MeetingMain/Index/" + conferenceMaster.ConferenceNickName,
						AttendenceId = result.ID
					});
					message.To.Add(to);
					//message.Attachments.Add(new Attachment(Server.MapPath(result.QRCode)));

					if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
					{
						foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
						{
							if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
							{
								message.Bcc.Add(new MailAddress(cc.Trim()));
							}
						}
					}

					var mailTask = Task.Run(() =>
					{
						sender.SendMail(from, message, conferenceMailServerMaster.Password);
					});
				}
				#endregion

				var userBox = new
				{
					isNewUser = isNewUser,
					mail = mailtxt,
					userName = userName,
					password = userName
				};

				return JsonCamelCase(new
				{
					data = userBox,
					code = "1",
					msg = "success"

				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取中文会议
		public async Task<JsonCamelCaseResult> GetMeetingDataMobile()
		{
			var sql = DbContext.ConferenceMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常
						&& !x.IsInternational
						&& x.IsDisplayMobile);

			sql = sql.OrderByDescending(x => x.ConferenceStartDate).ThenBy(x => x.Sort);
			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Id = x.ID,
				ConferenceName = x.ConferenceName,
				ConferenceStartDate = x.ConferenceStartDate.Value.ToString("yyyy-MM-dd"),
				ConferenceEndDate = ConstValues.strSpace + Resources.To + ConstValues.strSpace + x.ConferenceEndDate.Value.ToString("yyyy-MM-dd"),
				StartYear = x.ConferenceStartDate.Value.Year.ToString(),
				StartMonth = x.ConferenceStartDate.Value.Month.ToString("0#") + Resources.Month,
				StartDay = x.ConferenceStartDate.Value.Day.ToString("0#"),
				OperateLocation = x.OperateLocation,
				ConferenceAddress = string.IsNullOrEmpty(x.ConferenceAddress) ? string.Empty : x.ConferenceAddress,
				RegisterStartDate = x.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
				RegisterEndDate = x.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
				ConferenceNickName = x.ConferenceNickName,
				AllowRegister = x.RegisterStartDate.Value <= DateTime.Now && x.RegisterEndDate.Value >= DateTime.Now ? true : false,

			});

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);

		}

		//获取首页中文会议
		public async Task<JsonCamelCaseResult> GetHomeMeetingDataMobile()
		{
			var sql = DbContext.ConferenceMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常
						&& !x.IsInternational
						&& x.IsDisplayMobile
						&& x.IsDisplayMobileHome);

			sql = sql.OrderBy(x => x.Sort).ThenByDescending(x => x.ConferenceStartDate).Take(5);
			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Id = x.ID,
				ConferenceName = x.ConferenceName,
				ConferenceStartDate = x.ConferenceStartDate.Value.ToString("yyyy-MM-dd"),
				ConferenceEndDate = ConstValues.strSpace + Resources.To + ConstValues.strSpace + x.ConferenceEndDate.Value.ToString("yyyy-MM-dd"),
				StartYear = x.ConferenceStartDate.Value.Year.ToString(),
				StartMonth = x.ConferenceStartDate.Value.Month.ToString("0#") + Resources.Month,
				StartDay = x.ConferenceStartDate.Value.Day.ToString("0#"),
				OperateLocation = x.OperateLocation,
				ConferenceAddress = string.IsNullOrEmpty(x.ConferenceAddress) ? string.Empty : x.ConferenceAddress,
				RegisterStartDate = x.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
				RegisterEndDate = x.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
				ConferenceNickName = x.ConferenceNickName,
				AllowRegister = x.RegisterStartDate.Value <= DateTime.Now && x.RegisterEndDate.Value >= DateTime.Now ? true : false,

			});

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);

		}

		//获取英文会议
		public async Task<JsonCamelCaseResult> GetMeetingDataMobileEn()
		{
			var sql = DbContext.ConferenceMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常
						&& x.IsInternational
						&& x.IsDisplayMobile);

			sql = sql.OrderBy(x => x.Sort).ThenByDescending(x => x.ConferenceStartDate);
			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Id = x.ID,
				ConferenceName = x.ConferenceName,
				ConferenceStartDate = string.IsNullOrEmpty(x.OperateTime) ? string.Empty : x.OperateTime,
				ConferenceEndDate = string.Empty,
				StartYear = x.ConferenceStartDate.Value.Year.ToString(),
				StartMonth = x.ConferenceStartDate.Value.ToString("yyyy-MMM-dd").Substring(5, 3),
				StartDay = x.ConferenceStartDate.Value.Day.ToString("0#"),
				OperateLocation = x.OperateLocation,
				ConferenceAddress = string.IsNullOrEmpty(x.ConferenceAddress) ? string.Empty : x.ConferenceAddress,
				RegisterStartDate = x.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
				RegisterEndDate = x.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
				ConferenceNickName = x.ConferenceNickName,
				AllowRegister = x.RegisterStartDate.Value <= DateTime.Now && x.RegisterEndDate.Value >= DateTime.Now ? true : false,
			});

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);

		}

		//获取英文会议
		public async Task<JsonCamelCaseResult> GetHomeMeetingDataMobileEn()
		{
			var sql = DbContext.ConferenceMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常
						&& x.IsInternational
						&& x.IsDisplayMobile
						&& x.IsDisplayMobileHome);

			sql = sql.OrderByDescending(x => x.ConferenceStartDate).ThenBy(x => x.Sort).Take(5);
			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Id = x.ID,
				ConferenceName = x.ConferenceName,
				ConferenceStartDate = string.IsNullOrEmpty(x.OperateTime) ? string.Empty : x.OperateTime,
				ConferenceEndDate = string.Empty,
				StartYear = x.ConferenceStartDate.Value.Year.ToString(),
				StartMonth = x.ConferenceStartDate.Value.ToString("yyyy-MMM-dd").Substring(5, 3),
				StartDay = x.ConferenceStartDate.Value.Day.ToString("0#"),
				OperateLocation = x.OperateLocation,
				ConferenceAddress = string.IsNullOrEmpty(x.ConferenceAddress) ? string.Empty : x.ConferenceAddress,
				RegisterStartDate = x.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
				RegisterEndDate = x.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
				ConferenceNickName = x.ConferenceNickName,
				AllowRegister = x.RegisterStartDate.Value <= DateTime.Now && x.RegisterEndDate.Value >= DateTime.Now ? true : false,
			});

			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);

		}

		//登录
		public async Task<JsonCamelCaseResult> LoginMobile(string id, string pwd)
		{

			var data = await DbContext.SysUserMaster
						.FirstOrDefaultAsync(x => x.UserName == id || x.Mail == id);

			string password = string.Empty;
			if (!string.IsNullOrEmpty(pwd))
			{
				password = StringExtension.Encrypt(pwd);
			}

			if (data != null && data.Password == password)
			{
				var matchSSA = await DbContext.ViewUserRoleAction.AsNoTracking()
							.FirstOrDefaultAsync(x => x.UserName == data.UserName && x.RoleName == ConstValues.SA);

				var isSSA = false;
				if (matchSSA != null)
				{
					isSSA = true;
				}

				var conferenceIDList = DbContext.ViewConferenceRoleAction.AsNoTracking()
						.Where(x => x.UserName == data.UserName &&
								(x.RoleName == ConstValues.CA ||
								 (x.FunctionID == ConstValues.FunctionId.ConferenceContributeInfo &&
								 x.Modify == 1)))
						.Select(x => x.ConferenceID).ToList();

				var conferenceIds = conferenceIDList.Count > 0 ? string.Join(ConstValues.strSemicolon, conferenceIDList) : string.Empty;

				var attendIDList = DbContext.ConferenceAttendenceInfo.AsNoTracking()
						.Where(x => x.Creator == data.UserName)
						.Select(x => x.ConferenceId).ToList();

				var attendIds = attendIDList.Count > 0 ? string.Join(ConstValues.strSemicolon, attendIDList) : string.Empty;

				var result = new
				{
					Id = string.IsNullOrEmpty(data.ID) ? string.Empty : data.ID,
					UserName = string.IsNullOrEmpty(data.UserName) ? string.Empty : data.UserName,
					Password = StringExtension.Decrypt(data.Password),
					Mail = string.IsNullOrEmpty(data.Mail) ? string.Empty : data.Mail,
					FamilyName = string.IsNullOrEmpty(data.FamilyName) ? string.Empty : data.FamilyName,
					FirstName = string.IsNullOrEmpty(data.FirstName) ? string.Empty : data.FirstName,
					FullName = string.IsNullOrEmpty(data.FullName) ? string.Empty : data.FullName,
					Language = string.IsNullOrEmpty(data.Language) ? string.Empty : data.Language,
					Mobile = string.IsNullOrEmpty(data.Mobile) ? string.Empty : data.Mobile,
					NickName = string.IsNullOrEmpty(data.NickName) ? string.Empty : data.NickName,
					Telephone = string.IsNullOrEmpty(data.Telephone) ? string.Empty : data.Telephone,
					ZipCode = string.IsNullOrEmpty(data.ZipCode) ? string.Empty : data.ZipCode,
					Address = string.IsNullOrEmpty(data.Address) ? string.Empty : data.Address,
					Affiliation = string.IsNullOrEmpty(data.Affiliation) ? string.Empty : data.Affiliation,
					Birthday = data.Birthday.HasValue ? data.Birthday.Value.ToString("yyyy-MM-dd") : string.Empty,
					gender = data.Gender,
					HeadImg = Path.GetFileName(data.HeadImg),
					IsSSA = isSSA,
					ConferenceIds = conferenceIds,
					AttendIds = attendIds
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//登录IOS
		public async Task<JsonCamelCaseResult> LoginIOS(MobileLoginModel model)
		{
			var id = model.uid;
			var pwd = model.pass;

			var data = await DbContext.SysUserMaster
						.FirstOrDefaultAsync(x => x.UserName == id || x.Mail == id);

			string password = string.Empty;
			if (!string.IsNullOrEmpty(pwd))
			{
				password = StringExtension.Encrypt(pwd);
			}

			if (data != null && data.Password == password)
			{
				var matchSSA = await DbContext.ViewUserRoleAction.AsNoTracking()
							.FirstOrDefaultAsync(x => x.UserName == data.UserName && x.RoleName == ConstValues.SA);

				var isSSA = false;
				if (matchSSA != null)
				{
					isSSA = true;
				}

				var conferenceIDList = DbContext.ViewConferenceRoleAction.AsNoTracking()
						.Where(x => x.UserName == data.UserName &&
								(x.RoleName == ConstValues.CA ||
								 (x.FunctionID == ConstValues.FunctionId.ConferenceContributeInfo &&
								 x.Modify == 1)))
						.Select(x => x.ConferenceID).ToList();

				var conferenceIds = conferenceIDList.Count > 0 ? string.Join(ConstValues.strSemicolon, conferenceIDList) : string.Empty;

				var attendIDList = DbContext.ConferenceAttendenceInfo.AsNoTracking()
						.Where(x => x.Creator == data.UserName)
						.Select(x => x.ConferenceId).ToList();

				var attendIds = attendIDList.Count > 0 ? string.Join(ConstValues.strSemicolon, attendIDList) : string.Empty;

				var folder = ConstValues.SystemWeb + ConstValues.UserHeadImg.Replace(ConstValues.strWave, string.Empty);

				var result = new
				{
					Id = string.IsNullOrEmpty(data.ID) ? string.Empty : data.ID,
					UserName = string.IsNullOrEmpty(data.UserName) ? string.Empty : data.UserName,
					Password = StringExtension.Decrypt(data.Password),
					Mail = string.IsNullOrEmpty(data.Mail) ? string.Empty : data.Mail,
					FamilyName = string.IsNullOrEmpty(data.FamilyName) ? string.Empty : data.FamilyName,
					FirstName = string.IsNullOrEmpty(data.FirstName) ? string.Empty : data.FirstName,
					FullName = string.IsNullOrEmpty(data.FullName) ? string.Empty : data.FullName,
					Language = string.IsNullOrEmpty(data.Language) ? string.Empty : data.Language,
					Mobile = string.IsNullOrEmpty(data.Mobile) ? string.Empty : data.Mobile,
					NickName = string.IsNullOrEmpty(data.NickName) ? string.Empty : data.NickName,
					Telephone = string.IsNullOrEmpty(data.Telephone) ? string.Empty : data.Telephone,
					ZipCode = string.IsNullOrEmpty(data.ZipCode) ? string.Empty : data.ZipCode,
					Address = string.IsNullOrEmpty(data.Address) ? string.Empty : data.Address,
					Affiliation = string.IsNullOrEmpty(data.Affiliation) ? string.Empty : data.Affiliation,
					Birthday = data.Birthday.HasValue ? data.Birthday.Value.ToString("yyyy-MM-dd") : string.Empty,
					gender = data.Gender,
					HeadImg = folder + Path.GetFileName(data.HeadImg),
					IsSSA = isSSA,
					ConferenceIds = conferenceIds,
					AttendIds = attendIds
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

		}

		//android 注册
		public async Task<JsonResult> RegisterMobile(string userName, string familyName, string firstName, string affiliation, string mobile, string mail, string password)
		{
			var result = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.UserName == userName);
			if (result != null)
			{

				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			var mailcheck = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mail);
			if (mailcheck != null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "2",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			var newId = Utility.GetTableId(ConstValues.TableName.SysUserMaster);

			var user = new SysUserMaster
			{
				ID = newId,
				UserName = userName.Replace("~", " "),
				Password = StringExtension.Encrypt(password?.Trim()),
				FamilyName = familyName.Replace("~", " "),
				FirstName = firstName.Replace("~", " "),
				FullName = firstName.Replace("~", " ") + familyName.Replace("~", " "),
				Gender = true,
				Call = ConstValues.RegisterMobile.MR,
				Career = ConstValues.RegisterMobile.Career,
				OcisCode = ConstValues.RegisterMobile.OCIS,
				Affiliation = affiliation.Replace("~", " "),
				Mobile = mobile.Replace("~", " "),
				Mail = mail,
				Status = ConstValues.Status.暂停,
				Sort = ConstValues.DefaultSort,
				IsLocked = false,
				Creator = userName?.Trim(),
				CreateDate = DateTime.Now,
				HasSend = false
			};
			DbContext.SysUserMaster.Add(user);
			await DbContext.SaveChangesAsync();
			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		// IOS 注册
		public async Task<JsonResult> registerIOS(MobileRegisterModel model)
		{
			var userName = model.userName;
			var familyName = model.familyName;
			var firstName = model.firstName;
			var affiliation = model.affiliation;
			var mobile = model.mobile;
			var mail = model.mail;
			var password = model.password;

			var result = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.UserName == userName);
			if (result != null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			var mailcheck = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.Mail == mail);
			if (mailcheck != null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "2",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			var newId = Utility.GetTableId(ConstValues.TableName.SysUserMaster);

			var user = new SysUserMaster
			{
				ID = newId,
				UserName = userName,
				Password = StringExtension.Encrypt(password?.Trim()),
				FamilyName = familyName,
				FirstName = firstName,
				FullName = firstName + familyName,
				Gender = true,
				Call = ConstValues.RegisterMobile.MR,
				Career = ConstValues.RegisterMobile.Career,
				OcisCode = ConstValues.RegisterMobile.OCIS,
				Affiliation = affiliation,
				Mobile = mobile,
				Mail = mail,
				Status = ConstValues.Status.暂停,
				Sort = ConstValues.DefaultSort,
				IsLocked = false,
				Creator = userName?.Trim(),
				CreateDate = DateTime.Now,
				HasSend = false
			};
			DbContext.SysUserMaster.Add(user);
			await DbContext.SaveChangesAsync();
			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//忘记密码后发送邮件
		public async Task<ActionResult> sendPasswordMailMobile(string mail, string isZh)
		{
			var result = await DbContext.SysUserMaster
					.FirstOrDefaultAsync(x => x.Mail == mail);

			if (result == null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			result.PasswordFailed = ConstValues.intZero;
			result.IsLocked = false;
			await DbContext.SaveChangesAsync();

			var smtpServer = ConstValues.SmtpServer;
			var mailAddress = ConstValues.MailAddress;
			var password = ConstValues.MailPassword;

			var mailServer = await DbContext.SysMailServerMaster.AsNoTracking()
					.OrderBy(x => x.Sort)
					.ThenByDescending(x => x.UpdateDate)
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常);

			if (mailServer != null)
			{
				smtpServer = mailServer.MailServer;
				mailAddress = mailServer.Mail;
				password = mailServer.Password;
			}

			MailSender sender = new MailSender(smtpServer);
			MailAddress from = new MailAddress(mailAddress);
			MailAddress to = new MailAddress(result.Mail);

			MailMessage message = Utility.GetMailContent(new MailModel
			{
				MailRemark = ConstValues.MailSubject.找回密码,
				Language = result.Language,
				Mail = StringExtension.EncryptMail(mail),
				Password = StringExtension.Decrypt(result.Password)
			});
			message.To.Add(to);

			var strMsg = string.Empty;
			var mailTask = Task.Run(() =>
			{
				strMsg = sender.SendMail(from, message, password);
			});			
			if (string.IsNullOrEmpty(strMsg))
			{
				if (isZh == "false")
				{
					strMsg = "Password Has Sent to Your Email.";
				}
				else
				{
					strMsg = Resources.GetPasswordToMail;
				}
			}

			ModelState.AddModelError(string.Empty, strMsg);
			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = strMsg
			},
			JsonRequestBehavior.AllowGet);
		}

		//获取个人信息
		public async Task<JsonCamelCaseResult> GetUserInfoMobile(string id)
		{
			var data = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);

			var folder = ConstValues.SystemWeb + ConstValues.UserHeadImg.Replace(ConstValues.strWave, string.Empty);

			if (data != null)
			{
				var result = new
				{
					Id = data.ID,
					UserName = data.UserName,
					Password = StringExtension.Decrypt(data.Password),
					Mail = data.Mail,
					FamilyName = data.FamilyName,
					FirstName = data.FirstName,
					FullName = data.FullName,
					Language = data.Language,
					Mobile = data.Mobile,
					NickName = data.NickName,
					Telephone = data.Telephone,
					ZipCode = data.ZipCode,
					Address = data.Address,
					Affiliation = data.Affiliation,
					Birthday = data.Birthday,
					gender = data.Gender,
					HeadImg = folder + Path.GetFileName(data.HeadImg),
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取参会记录
		public async Task<JsonCamelCaseResult> GetProfileAttendInfoMobile(string id, string language)
		{
			var user = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);



			if (user != null)
			{
				var attendenceIdList = DbContext.ProfilePaymentRecord.AsNoTracking()
							.GroupBy(x => x.AttendenceId)
							.Select(x => new ProfileRecModel
							{
								AttendenceId = x.Key,
								Count = x.Count()
							}).ToList();

				var queryTemp = from a in DbContext.ProfilePaymentRecord.AsNoTracking()
						group a by a.AttendenceId into g
						select new { g.Key, g };

				bool isInternationalOrNot = false;

				if (language != "zh")
				{
					isInternationalOrNot = true;
				}

				var sql = from conferenceAttendenceInfo in DbContext.ConferenceAttendenceInfo.AsNoTracking()
						.Where(x => x.Creator == user.UserName)
					  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking().Where(x => x.IsInternational == isInternationalOrNot)
					       on conferenceAttendenceInfo.ConferenceId equals conferenceMaster.ID
					  join tran in DbContext.TransferEvidenceMaster.AsNoTracking()
					       on conferenceAttendenceInfo.ID equals tran.AttendenceId into t1
					  from trane in t1.DefaultIfEmpty()
					  join record in queryTemp
					       on conferenceAttendenceInfo.ID equals record.Key into t2
					  from rec in t2.DefaultIfEmpty()
					  join conferencePaymentMaster in DbContext.ConferencePaymentMaster.AsNoTracking()
					      on conferenceAttendenceInfo.PaymentTypeId equals conferencePaymentMaster.ID into t3
					  from conferencePaymentMaster in t3.DefaultIfEmpty()
					  join sysPaymentMaster in DbContext.SysPaymentMaster.AsNoTracking()
						on conferencePaymentMaster.PayId equals sysPaymentMaster.ID into t4
					  from sysPaymentMaster in t4.DefaultIfEmpty()
					  orderby conferenceMaster.ConferenceStartDate descending
					  select new
					  {
						  ConferenceId = conferenceMaster.ID,
						  Id = conferenceAttendenceInfo.ID,
						  ConferenceName = conferenceMaster.ConferenceName,
						  ConferenceOperateLocation = conferenceMaster.OperateLocation,
						  ConferenceAddress = conferenceMaster.ConferenceAddress,
						  ConferenceStartDate = conferenceMaster.ConferenceStartDate,
						  ConferenceEndDate = conferenceMaster.ConferenceEndDate,
						  RegisterStartDate = conferenceMaster.RegisterStartDate,
						  RegisterEndDate = conferenceMaster.RegisterEndDate,
						  FullName = conferenceAttendenceInfo.FullName,
						  Creator = conferenceAttendenceInfo.Creator,
						  HasVisa = conferenceAttendenceInfo.HasVisa,
						  Currency = conferenceAttendenceInfo.Currency,
						  Discount = conferenceAttendenceInfo.Discount,
						  TotalFee = conferenceAttendenceInfo.TotalFee,
						  HasPaid = conferenceAttendenceInfo.HasPaid,
						  CreateDate = conferenceAttendenceInfo.CreateDate,
						  Sort = conferenceAttendenceInfo.Sort.Value,
						  UploadUrl = trane.UploadUrl,
						  PayStartDate = conferenceMaster.PayStartDate,
						  PayEndDate = conferenceMaster.PayEndDate,
						  ConferenceNickName = conferenceMaster.ConferenceNickName,
						  BenefitEndDate = conferenceMaster.BenefitEndDate,
						  BenefitStartDate = conferenceMaster.BenefitStartDate,
						  HomePageUrl = conferenceMaster.HomePageUrl,
						  PaymentTypeId = conferenceAttendenceInfo.PaymentTypeId,
						  PaymentName = sysPaymentMaster.PaymentName,
						  PaymentNameEn = sysPaymentMaster.PaymentNameEn,
						  IsInternational = conferenceMaster.IsInternational,
						  OperateTime = conferenceMaster.OperateTime
					  };

				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					ConferenceId = x.ConferenceId,
					ConferenceName = x.ConferenceName,
					ConferenceOperateLocation = x.ConferenceOperateLocation,
					ConferenceAddress = string.IsNullOrEmpty(x.ConferenceAddress) ? string.Empty : x.ConferenceAddress,
					ConferenceStartDate = x.IsInternational ? (string.IsNullOrEmpty(x.OperateTime) ? string.Empty : x.OperateTime) : x.ConferenceStartDate.Value.ToString("yyyy-MM-dd"),
					ConferenceEndDate = x.IsInternational ? string.Empty : ConstValues.strSpace + Resources.To + ConstValues.strSpace + x.ConferenceEndDate.Value.ToString("yyyy-MM-dd"),
					RegisterStartDate = x.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
					RegisterEndDate = x.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
					FullName = x.FullName == null ? string.Empty : x.FullName,
					Id = x.Id,
					Currency = x.Currency,
					TotalFee = x.BenefitStartDate < DateTime.Now && DateTime.Now < x.BenefitEndDate ? x.Discount.Value.ToString("N2") : x.TotalFee.Value.ToString("N2"),
					HasPaid = x.HasPaid,
					HasVisa = x.HasVisa,
					RegistrationTime = !x.IsInternational ? x.CreateDate.Value.ToString("yyyy-MM-dd") : x.CreateDate.Value.ToString("MM/dd/yyyy"),
					PaymentDetail = x.HasPaid,
					Creator = x.Creator,
					UploadUrl = x.UploadUrl,
					PayStartDate = x.PayStartDate.Value.ToString("yyyy-MM-dd"),
					PayEndDate = x.PayEndDate.Value.ToString("yyyy-MM-dd"),
					ConferenceNickName = x.ConferenceNickName,
					HomePageUrl = x.HomePageUrl,
					PaymentTypeId = x.PaymentTypeId,
					HasTran = DbContext.ConferenceFunctionMaster.AsNoTracking().Any(e => e.ConferenceId == x.ConferenceId &&
								e.Status == ConstValues.Status.正常 && e.FunctionId == ConstValues.FunctionId.ConferenceTransferEvidence),
					PayName = x.IsInternational ? x.PaymentNameEn : x.PaymentName,
					payLanguage = x.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn,
					VisaRequired = DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa") == null ?
								false : DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa").IsRequired,
					VisaStatus = DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa") == null ?
								ConstValues.Status.暂停 : DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa").Status,
					ConferenceEndTime = x.ConferenceEndDate.Value.ToString("yyyy-MM-dd"),
					VisaBtnCanChoose = DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa") == null ?
								false : (DbContext.ConferenceAttendenceForm.AsNoTracking().FirstOrDefault(y => y.ConferenceId == x.ConferenceId && y.Key == "Visa").Status == ConstValues.Status.暂停 ? false : true)
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//修改个人信息
		public async Task<JsonCamelCaseResult> UpdateUserMobile(string id, string pam, string type)
		{
			var user = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.ID == id);

			if (user != null)
			{
				if (type == "gender")
				{
					if (pam == "1")
					{
						user.Gender = true;
						user.Call = ConstValues.RegisterMobile.MR;
					}
					else
					{
						user.Gender = false;
						user.Call = ConstValues.RegisterMobile.MS;
					}
				}
				else if (type == "familyName")
				{
					user.FamilyName = pam.Replace("~", " ");
				}
				else if (type == "firstName")
				{
					user.FirstName = pam.Replace("~", " ");
				}
				else if (type == "affiliation")
				{
					user.Affiliation = pam.Replace("~", " ");
				}
				else if (type == "mobile")
				{
					user.Mobile = pam.Replace("~", " ");
				}
				user.Updater = user.UserName;
				user.UpdateDate = DateTime.Now;

				user.Status = ConstValues.Status.正常;
				await DbContext.SaveChangesAsync();

				return JsonCamelCase(new
				{
					data = "",
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取个人发票信息
		public async Task<JsonCamelCaseResult> GetUserInvoiceInfoMobile(string id)
		{
			var data = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);

			var folder = ConstValues.SystemWeb + ConstValues.UserHeadImg.Replace(ConstValues.strWave, string.Empty);

			if (data != null)
			{
				var result = new
				{
					Id = data.ID,
					UserName = data.UserName,
					InvoiceTitle = string.IsNullOrEmpty(data.InvoiceTitle) ? string.Empty : data.InvoiceTitle,
					TaxNum = string.IsNullOrEmpty(data.TaxNum) ? string.Empty : data.TaxNum,
					AddressAndTel = string.IsNullOrEmpty(data.AddressAndTel) ? string.Empty : data.AddressAndTel,
					Bank = string.IsNullOrEmpty(data.Bank) ? string.Empty : data.Bank,
					BankAccount = string.IsNullOrEmpty(data.BankAccount) ? string.Empty : data.BankAccount
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//填写会议的发票信息android
		public async Task<JsonCamelCaseResult> VisaSubmitMobile(string attendId, string conferenceId, string userName, string mailtxt, string lastNametxt, string firstNametxt,
				string affiliationtxt, string addresstxt, string zipcodetxt, string teltxt, string passportNotxt, string passportCountrytxt,
				string remarktxt, string gendertxt, string titletxt, string countrytxt, string statetxt, string citytxt, string brithdaytxt,
				string issueDatetxt, string expiryDatetxt, string arrivalDatetxt, string departuralDatetxt)
		{
			var visa = await DbContext.VisaInfo.FirstOrDefaultAsync(x => x.AttendenceId == attendId);
			int countryVal = 0;
			string titleVal = null;
			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.NameEn == countrytxt.Replace("~", " "));
			if (country != null)
			{
				countryVal = country.ID;
			}
			var title = await DbContext.TitleMaster.FirstOrDefaultAsync(x => x.TitleName == titletxt.Replace("~", " ") && x.ConferenceId == conferenceId);
			if (title != null)
			{
				titleVal = title.ID;
			}

			DateTime brithdayDT = DateTime.ParseExact(brithdaytxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime issueDT = DateTime.ParseExact(issueDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime expiryDT = DateTime.ParseExact(expiryDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime arrivalDT = DateTime.ParseExact(arrivalDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime departuralDT = DateTime.ParseExact(departuralDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);

			if (visa == null)
			{
				var visaInfo = new VisaInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.VisaInfo),
					ConferenceId = conferenceId,
					AttendenceId = attendId,
					FirstName = firstNametxt?.Replace("~", " "),
					FamilyName = lastNametxt?.Replace("~", " "),
					FullName = Utility.SetFullName(lastNametxt?.Replace("~", " "), firstNametxt?.Replace("~", " "), ConstValues.Language.En),
					Title = titleVal,
					Affiliation = affiliationtxt?.Replace("~", " "),
					StateStr = statetxt?.Replace("~", " "),
					CityStr = citytxt?.Replace("~", " "),
					Address = addresstxt?.Replace("~", " "),
					ZipCode = zipcodetxt?.Replace("~", " "),
					Mail = mailtxt?.Replace("~", " "),
					Telephone = teltxt?.Replace("~", " "),
					Birthdate = brithdayDT,
					Gender = gendertxt == "true" ? true : false,
					PassportNum = passportNotxt?.Replace("~", " "),
					IssueOfCountry = passportCountrytxt?.Replace("~", " "),
					DateOfIssue = issueDT,
					ExpiryDate = expiryDT,
					ArrivalDate = arrivalDT,
					DeparturalDate = departuralDT,
					Remark = remarktxt?.Replace("~", " "),
					Status = ConstValues.InvitationStatus.已申请,
					SendStatus = ConstValues.SendStatus.未发送,
					Creator = userName,
					CreateDate = DateTime.Now,
					//CreateIP = LoginUser.IP,
				};
				if (countryVal != 0)
				{
					visaInfo.Country = countryVal;
				}

				DbContext.VisaInfo.Add(visaInfo);

				var conferenceAttendenceInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);
				if (conferenceAttendenceInfo != null)
				{
					conferenceAttendenceInfo.HasVisa = true;
				}
				await DbContext.SaveChangesAsync();
				return JsonCamelCase(new
				{
					data = "",
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//填写会议的发票信息IOS
		public async Task<JsonCamelCaseResult> VisaSubmitIOS(MobileVisaInfoModel model)
		{
			var attendId = model.attendId;
			var conferenceId = model.conferenceId;
			var userName = model.userName;
			var mailtxt = model.mailtxt;
			var lastNametxt = model.lastNametxt;
			var firstNametxt = model.firstNametxt;
			var affiliationtxt = model.affiliationtxt;
			var addresstxt = model.addresstxt;
			var zipcodetxt = model.zipcodetxt;
			var teltxt = model.teltxt;
			var passportNotxt = model.passportNotxt;
			var passportCountrytxt = model.passportCountrytxt;
			var remarktxt = model.remarktxt;
			var gendertxt = model.gendertxt;
			var titletxt = model.titletxt;
			var countrytxt = model.countrytxt;
			var statetxt = model.statetxt;
			var citytxt = model.citytxt;
			var brithdaytxt = model.brithdaytxt;
			var issueDatetxt = model.issueDatetxt;
			var expiryDatetxt = model.expiryDatetxt;
			var arrivalDatetxt = model.arrivalDatetxt;
			var departuralDatetxt = model.departuralDatetxt;

			var visa = await DbContext.VisaInfo.FirstOrDefaultAsync(x => x.AttendenceId == attendId);
			int countryVal = 0;
			string titleVal = null;
			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.NameEn == countrytxt.Replace("~", " "));
			if (country != null)
			{
				countryVal = country.ID;
			}
			var title = await DbContext.TitleMaster.FirstOrDefaultAsync(x => x.TitleName == titletxt.Replace("~", " ") && x.ConferenceId == conferenceId);
			if (title != null)
			{
				titleVal = title.ID;
			}

			DateTime brithdayDT = DateTime.ParseExact(brithdaytxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime issueDT = DateTime.ParseExact(issueDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime expiryDT = DateTime.ParseExact(expiryDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime arrivalDT = DateTime.ParseExact(arrivalDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);
			DateTime departuralDT = DateTime.ParseExact(departuralDatetxt, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture);

			if (visa == null)
			{
				var visaInfo = new VisaInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.VisaInfo),
					ConferenceId = conferenceId,
					AttendenceId = attendId,
					FirstName = firstNametxt?.Replace("~", " "),
					FamilyName = lastNametxt?.Replace("~", " "),
					FullName = Utility.SetFullName(lastNametxt?.Replace("~", " "), firstNametxt?.Replace("~", " "), ConstValues.Language.En),
					Title = titleVal,
					Affiliation = affiliationtxt?.Replace("~", " "),
					StateStr = statetxt?.Replace("~", " "),
					CityStr = citytxt?.Replace("~", " "),
					Address = addresstxt?.Replace("~", " "),
					ZipCode = zipcodetxt?.Replace("~", " "),
					Mail = mailtxt?.Replace("~", " "),
					Telephone = teltxt?.Replace("~", " "),
					Birthdate = brithdayDT,
					Gender = gendertxt == "true" ? true : false,
					PassportNum = passportNotxt?.Replace("~", " "),
					IssueOfCountry = passportCountrytxt?.Replace("~", " "),
					DateOfIssue = issueDT,
					ExpiryDate = expiryDT,
					ArrivalDate = arrivalDT,
					DeparturalDate = departuralDT,
					Remark = remarktxt?.Replace("~", " "),
					Status = ConstValues.InvitationStatus.已申请,
					SendStatus = ConstValues.SendStatus.未发送,
					Creator = userName,
					CreateDate = DateTime.Now,
					//CreateIP = LoginUser.IP,
				};
				if (countryVal != 0)
				{
					visaInfo.Country = countryVal;
				}

				DbContext.VisaInfo.Add(visaInfo);

				var conferenceAttendenceInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);
				if (conferenceAttendenceInfo != null)
				{
					conferenceAttendenceInfo.HasVisa = true;
				}
				await DbContext.SaveChangesAsync();
				return JsonCamelCase(new
				{
					data = "",
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 移动端获取报告信息
		/// 第三页
		/// zyq
		/// </summary>
		public async Task<JsonCamelCaseResult> GetReporterInfo(string contributeId)
		{
			var contributeinfo = await DbContext.ConferenceContributeInfo.FirstOrDefaultAsync(x => x.ID == contributeId);

			if (contributeinfo != null)
			{
				var conferenceMaster = DbContext.ConferenceMaster.FirstOrDefault(x => x.ID == contributeinfo.ConferenceId);
				var author = DbContext.AuthorInfo.Where(x => x.ContributeId == contributeId && x.Status == ConstValues.Status.正常).OrderBy(x => x.Sort).ThenBy(x => x.CreateDate).ToList();
				var pInfo = "";
				author.ForEach(x =>
				{
					if (x.IsPresenter)
					{
						pInfo = x.SelfIntroduction;
					}
					x.Affiliation = conferenceMaster.IsInternational ?
								Utility.GetAllAffiliationEn(contributeinfo.ConferenceId, x.Mail, x.ContributeId, ConstValues.strComma) :
								Utility.GetAllAffiliation(contributeinfo.ConferenceId, x.Mail, x.ContributeId, ConstValues.strCommaCn);
				});
				string strText = "";
				if (!string.IsNullOrEmpty(contributeinfo.Abstract))
				{
					strText = Utility.GetNoHtmlLeaveSubSup(contributeinfo.Abstract);
				}

				var result = new
				{
					Id = contributeinfo.ID,
					Abstract = strText,
					PersonInfo = string.IsNullOrEmpty(pInfo) ? string.Empty : pInfo,
					Author = author
				};
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				var result = new { };
				return JsonCamelCase(new
				{
					data = result,
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取会议开始时间
		public async Task<JsonCamelCaseResult> GetConferenceOperateDate(string conferenceId)
		{
			var conference = await DbContext.ConferenceMaster.FirstOrDefaultAsync(x => x.ID == conferenceId);
			if (conference != null)
			{
				var result = new
				{
					ConferenceStartDate = conference.ConferenceStartDate.HasValue ? conference.ConferenceStartDate.Value.ToString("yyyy-MM-dd") : string.Empty,
					ConferenceEndDate = conference.ConferenceEndDate.HasValue ? conference.ConferenceEndDate.Value.ToString("yyyy-MM-dd") : string.Empty
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//参会注册获取title
		public async Task<JsonResult> GetTitleMobile(string conferenceId)
		{
			var sql = DbContext.TitleMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.TitleName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.TitleName
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//参会注册获取参会身份
		public async Task<JsonResult> GetAttendenceIdentityMobile(string conferenceId)
		{
			var sql = DbContext.AttendenceIdentityMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.IdentityName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.IdentityName
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 移动端 国家
		/// </summary>
		public async Task<JsonResult> GetCountryMobile()
		{

			var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.Level == ConstValues.LocationLevel.国家)
				.OrderBy(x => x.Name);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.Name,
					Haschild = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(y => y.ParentId == x.ID) == null ? false.ToString() : true.ToString()
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 移动端 州
		/// </summary>
		public async Task<JsonResult> GetStateMobile(string countryName)
		{

			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == countryName || x.NameEn == countryName);
			if (country != null)
			{
				var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.ParentId == country.ID)
				.OrderBy(x => x.Name);
				if (sql != null)
				{
					var sqlResult = await sql.ToListAsync();
					var result = sqlResult.Select(x => new
					{
						Id = x.ID,
						Name = x.Name,
						Haschild = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(y => y.ParentId == x.ID) == null ? false.ToString() : true.ToString()
					});

					return JsonCamelCase(new
					{
						data = result,
						code = "1",
						msg = "success"
					},
					JsonRequestBehavior.AllowGet);
				}
				else
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
		}

		/// <summary>
		/// 移动端 市
		/// </summary>
		public async Task<JsonResult> GetCityMobile(string stateName)
		{
			var state = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == stateName || x.NameEn == stateName);
			if (state != null)
			{
				var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.ParentId == state.ID)
				.OrderBy(x => x.Name);
				if (sql != null)
				{
					var sqlResult = await sql.ToListAsync();
					var result = sqlResult.Select(x => new
					{
						Id = x.ID,
						Name = x.Name
					});

					return JsonCamelCase(new
					{
						data = result,
						code = "1",
						msg = "success"
					},
					JsonRequestBehavior.AllowGet);
				}
				else
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
		}

		/// <summary>
		/// 移动端 国家
		/// </summary>
		public async Task<JsonResult> GetCountryEnMobile()
		{
			var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.Level == ConstValues.LocationLevel.国家)
				.OrderBy(x => x.NameEn);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.NameEn,
					Haschild = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(y => y.ParentId == x.ID) == null ? false.ToString() : true.ToString()
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 移动端 州
		/// </summary>
		public async Task<JsonResult> GetStateEnMobile(string countryName)
		{
			var country = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == countryName || x.NameEn == countryName);
			if (country != null)
			{
				var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.ParentId == country.ID)
				.OrderBy(x => x.NameEn);
				if (sql != null)
				{
					var sqlResult = await sql.ToListAsync();
					var result = sqlResult.Select(x => new
					{
						Id = x.ID,
						Name = x.NameEn,
						Haschild = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(y => y.ParentId == x.ID) == null ? false.ToString() : true.ToString()
					});

					return JsonCamelCase(new
					{
						data = result,
						code = "1",
						msg = "success"
					},
					JsonRequestBehavior.AllowGet);
				}
				else
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
		}

		/// <summary>
		/// 移动端 市
		/// </summary>
		public async Task<JsonResult> GetCityEnMobile(string stateName)
		{
			var state = await DbContext.LocationMaster.FirstOrDefaultAsync(x => x.Name == stateName || x.NameEn == stateName);
			if (state != null)
			{
				var sql = DbContext.LocationMaster.AsNoTracking()
				.Where(x => x.ParentId == state.ID)
				.OrderBy(x => x.NameEn);
				if (sql != null)
				{
					var sqlResult = await sql.ToListAsync();
					var result = sqlResult.Select(x => new
					{
						Id = x.ID,
						Name = x.NameEn
					});

					return JsonCamelCase(new
					{
						data = result,
						code = "1",
						msg = "success"
					},
					JsonRequestBehavior.AllowGet);
				}
				else
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}
		}

		/// <summary>
		/// 移动端获取会议的支付方式
		/// </summary>
		public async Task<JsonResult> GetPayTypeMobile(string conferenceId)
		{
			var result = await DbContext.ConferencePaymentMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId)
					.Join(DbContext.SysPaymentMaster.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常),
						pay => pay.PayId,
						master => master.ID,
						(pay, master) => new
						{
							Id = pay.ID,
							Name = master.PaymentName,
							Sort = pay.Sort
						})
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Name)
					.ToListAsync();

			if (result != null)
			{
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		/// <summary>
		/// 移动端获取会议的支付方式
		/// </summary>
		public async Task<JsonResult> GetPayTypeEnMobile(string conferenceId)
		{
			var result = await DbContext.ConferencePaymentMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId)
					.Join(DbContext.SysPaymentMaster.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常),
						pay => pay.PayId,
						master => master.ID,
						(pay, master) => new
						{
							Id = pay.ID,
							Name = master.PaymentNameEn,
							Sort = pay.Sort
						})
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Name)
					.ToListAsync();

			if (result != null)
			{
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//参会注册获取发票明细
		public async Task<JsonResult> GetInvoiceDetailMobile(string conferenceId)
		{
			var sql = DbContext.ConferenceInvoiceMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.InvoiceDetail);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.InvoiceDetail
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonResult> GetAttendenceFeeMobile(string conferenceId, string currency)
		{
			var sql = DbContext.FeeAttendenceMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.Currency == currency);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.RegisterType);
			bool isfavourable = false;
			var conferenceMaster = DbContext.ConferenceMaster.FirstOrDefault(x => x.ID == conferenceId);
			if (conferenceMaster != null)
			{
				isfavourable = (conferenceMaster.BenefitStartDate <= DateTime.Now && DateTime.Now <= conferenceMaster.BenefitEndDate) ? true : false;
			}
			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.RegisterType + ConstValues.chrColon + ConstValues.chrSpace + x.Currency + ConstValues.chrSpace + (isfavourable ? x.Discount.Value.ToString("N2") : x.Price.Value.ToString("N2")),
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonResult> GetMealFeeMobile(string conferenceId, string currency)
		{
			var sql = DbContext.FeeMealMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.Currency == currency);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.FeeName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.FeeName + ConstValues.chrColon + ConstValues.chrSpace + x.Currency + ConstValues.chrSpace + x.Price.Value.ToString("N2"),
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonResult> GetPageFeeMobile(string conferenceId, string currency)
		{
			var sql = DbContext.FeePageMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.Currency == currency);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.FeeName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.FeeName + ConstValues.chrColon + ConstValues.chrSpace + x.Currency + ConstValues.chrSpace + x.Price.Value.ToString("N2"),
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonResult> GetConcurrentEventMobile(string conferenceId, string identityName, string currencytxt)
		{
			var currency = currencytxt == "false" ? ConstValues.Currency.美元 : ConstValues.Currency.人民币;
			var result = await DbContext.ConcurrentEventMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId)
					.OrderBy(x => x.Sort)
					.ToListAsync();

			var attendenceIdentityMaster = await DbContext.AttendenceIdentityMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId
						&& x.IdentityName == identityName.Replace("~", " ") && x.Status == ConstValues.Status.正常);
			var identity = "";
			if (attendenceIdentityMaster != null)
			{
				identity = attendenceIdentityMaster.ID;
			}


			var newResult = result.Select(x => new
			{
				id = x.ID,
				eventName = x.EventName,
				eventPlace = x.EventPlace,
				eventTime = x.EventTime,
				link = x.Link,
				contact = CombineContact(x.Contact, x.ContactPhone),

				//contactPhone = x.ContactPhone == null ? string.Empty : x.ContactPhone,
				//mail = concurrentevent.mail
				fee = Utility.GetFeeAndIdentity(x.ID, x.IsAllIdentity, currency),
				hasEvent = Utility.HasEvent(x.ID, identity, currency),
				number = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ConcurrentEventId == x.ID && y.Currency == currency
						&& (y.AttendenceIdentityId == ConstValues.ApplicableForAll || y.AttendenceIdentityId == identity))?.Number,
				price = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(y => y.ConcurrentEventId == x.ID && y.Currency == currency
						&& (y.AttendenceIdentityId == ConstValues.ApplicableForAll || y.AttendenceIdentityId == identity))?.Price.ToString(),
				currency = currency,

			}).ToList();


			if (newResult != null)
			{
				return JsonCamelCase(new
				{
					data = newResult,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public string CombineContact(string contact, string contactPhone)
		{
			var returnString = "";
			if (!string.IsNullOrEmpty(contact))
			{
				returnString += contact;
			}
			if (!string.IsNullOrEmpty(contactPhone))
			{
				if (returnString != "")
				{
					returnString += ConstValues.chrComma + ConstValues.strSpace;
					returnString += contactPhone;
				}
				else
				{
					returnString += contactPhone;
				}
			}
			return returnString;
		}

		public async Task<JsonResult> GetOtherFeeMobile(string conferenceId, string currencytxt)
		{
			var currency = currencytxt == "false" ? ConstValues.Currency.美元 : ConstValues.Currency.人民币;
			var sql = DbContext.FeeOtherMaster.AsNoTracking()
				.Where(x => x.ConferenceId == conferenceId && x.Status == ConstValues.Status.正常 && x.Currency == currency);

			sql = sql.OrderBy(x => x.Sort).ThenBy(x => x.FeeName);

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					Name = x.FeeName,
					Currency = x.Currency,
					MinCount = x.MinCount.Value.ToString(),
					MaxCount = x.MaxCount.Value.ToString(),
					Price = x.Price.Value.ToString()
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonResult> GetFavouriteTopicMobile(string conferenceId)
		{
			var result = await DbContext.TopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.TopicName)
					.Select(x => new
					{
						Id = x.ID,
						Name = x.TopicName
					})
					.ToListAsync();
			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
				JsonRequestBehavior.AllowGet);


		}

		public async Task<JsonResult> GetFeeDetail(string attendId)
		{
			var attendInfo = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);

			double? attendFee = 0.00;
			double? pageFee = 0.00;
			double? mealFee = 0.00;
			double? otherFee = 0.00;
			double? eventFee = 0.00;
			double? totalFee = 0.00;

			if (attendInfo != null)
			{
				var conference = await DbContext.ConferenceMaster.FirstOrDefaultAsync(x => x.ID == attendInfo.ConferenceId);

				//参会费
				var attendFeeInfo = await DbContext.ProfilePaymentInfo
						.FirstOrDefaultAsync(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.参会费 && x.Fee > 0);
				if (attendFeeInfo != null)
				{
					attendFee = conference.BenefitStartDate < DateTime.Now && DateTime.Now < conference.BenefitEndDate ? attendFeeInfo.Discount : attendFeeInfo.Fee;
				}
				//版面费
				var pageFeeInfo = await DbContext.ProfilePaymentInfo
						.FirstOrDefaultAsync(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.版面费 && x.Fee > 0);
				if (pageFeeInfo != null)
				{
					pageFee = conference.BenefitStartDate < DateTime.Now && DateTime.Now < conference.BenefitEndDate ? pageFeeInfo.Discount : pageFeeInfo.Fee;
				}
				//餐费
				var mealFeeInfo = await DbContext.ProfilePaymentInfo
						.FirstOrDefaultAsync(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.餐费 && x.Fee > 0);
				if (mealFeeInfo != null)
				{
					mealFee = conference.BenefitStartDate < DateTime.Now && DateTime.Now < conference.BenefitEndDate ? mealFeeInfo.Discount : mealFeeInfo.Fee;
				}
				//其他费用
				var otherFeeInfo = DbContext.ProfilePaymentInfo.AsNoTracking()
						.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.其他费用 && x.Fee > 0)
						.ToList();
				if (otherFeeInfo.Count > 0)
				{
					for (var index = 0; index < otherFeeInfo.Count; index++)
					{
						otherFee += conference.BenefitStartDate < DateTime.Now && DateTime.Now < conference.BenefitEndDate ? otherFeeInfo[index].Discount : otherFeeInfo[index].Fee;
					}
				}
				//同期活动费用
				var eventFeeInfo = DbContext.ProfilePaymentInfo.AsNoTracking()
						.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费 && x.Fee > 0)
						.ToList();
				if (eventFeeInfo.Count > 0)
				{
					for (var index = 0; index < eventFeeInfo.Count; index++)
					{
						eventFee += conference.BenefitStartDate < DateTime.Now && DateTime.Now < conference.BenefitEndDate ? eventFeeInfo[index].Discount : eventFeeInfo[index].Fee;
					}
				}

				var currency = attendInfo.Currency;

				totalFee = attendFee + pageFee + mealFee + otherFee + eventFee;

				var result = new
				{
					AttendFee = attendFee,
					PageFee = pageFee,
					MealFee = mealFee,
					OtherFee = otherFee,
					EventFee = eventFee,
					TotalFee = totalFee,
					Currency = string.IsNullOrEmpty(currency) ? string.Empty : currency
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

		}

		public async Task<JsonResult> GetAttendenceInfoByMail(string mail, string conferenceId)
		{
			var attendenceInfo = await DbContext.ConferenceAttendenceInfo.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Mail == mail && x.ConferenceId == conferenceId);

			if (attendenceInfo == null)
			{
				var userInfo = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.Mail == mail);

				if (userInfo != null)
				{
					var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.ID == conferenceId);

					var infoEn = await DbContext.SysUserMasterEn.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Mail == mail);

					var info = await DbContext.SysUserMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.Mail == mail);

					if (conferenceInfo.IsInternational && infoEn != null)
					{
						var result = new
						{
							Mail = infoEn.Mail,
							FamilyName = infoEn.FamilyName,
							FirstName = infoEn.FirstName,
							FullName = infoEn.FullName,
							Gender = infoEn.Gender,
							Degree = infoEn.Degree == 0 ? string.Empty :
									DbContext.DegreeMaster.AsNoTracking().FirstOrDefault(x => x.ID == infoEn.Degree)?.DegreeNameEn,
							Country = infoEn.Country == null ? string.Empty :
									DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == infoEn.Country)?.NameEn,
							State = infoEn.StateStr,
							City = infoEn.CityStr,
							Address = infoEn.Address == null ? string.Empty : infoEn.Address,
							Telephone = infoEn.Telephone == null ? string.Empty : infoEn.Telephone,
							Mobile = infoEn.Mobile == null ? string.Empty : infoEn.Mobile,
							Affiliation = infoEn.Affiliation == null ? string.Empty : infoEn.Affiliation,
							Department = infoEn.Department == null ? string.Empty : infoEn.Department,
							Job = Utility.GetNameFromIdList(infoEn.Career, "career", ConstValues.Language.En),
							EssayId = string.Empty,
							FavouriteTopicId = string.Empty,
							HasVisa = false,
							HasHotel = false,
							HasMeal = false,
							HasPage = false,
							TotalFee = 0,
							Discount = 0,
							InvoiceTitle = info.InvoiceTitle == null ? string.Empty : info.InvoiceTitle,
							TaxNum = info.TaxNum == null ? string.Empty : info.TaxNum,
							AddressAndTel = info.AddressAndTel == null ? string.Empty : info.AddressAndTel,
							Bank = info.Bank == null ? string.Empty : info.Bank,
							BankAccount = info.BankAccount == null ? string.Empty : info.BankAccount,
						};
						return JsonCamelCase(new
						{
							data = result,
							code = "1",
							msg = "success"
						},
						JsonRequestBehavior.AllowGet);
					}
					else
					{
						var result = new
						{
							Mail = info.Mail,
							FamilyName = info.FamilyName,
							FirstName = info.FirstName,
							FullName = info.FullName,
							Gender = info.Gender,
							Degree = info.Degree == null ? string.Empty :
										DbContext.DegreeMaster.AsNoTracking().FirstOrDefault(x => x.ID == info.Degree)?.DegreeName,
							Country = info.Country == null ? string.Empty :
										DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == info.Country)?.Name,
							State = info.StateStr,
							City = info.CityStr,
							Address = info.Address == null ? string.Empty : info.Address,
							Telephone = info.Telephone == null ? string.Empty : info.Telephone,
							Mobile = info.Mobile == null ? string.Empty : info.Mobile,
							Affiliation = info.Affiliation == null ? string.Empty : info.Affiliation,
							Department = info.Department == null ? string.Empty : info.Department,
							Job = Utility.GetNameFromIdList(info.Career, "career", ConstValues.Language.Cn),
							EssayId = string.Empty,
							FavouriteTopicId = string.Empty,
							HasVisa = false,
							HasHotel = false,
							HasMeal = false,
							HasPage = false,
							TotalFee = 0,
							Discount = 0,
							InvoiceTitle = info.InvoiceTitle == null ? string.Empty : info.InvoiceTitle,
							TaxNum = info.TaxNum == null ? string.Empty : info.TaxNum,
							AddressAndTel = info.AddressAndTel == null ? string.Empty : info.AddressAndTel,
							Bank = info.Bank == null ? string.Empty : info.Bank,
							BankAccount = info.BankAccount == null ? string.Empty : info.BankAccount,
						};
						return JsonCamelCase(new
						{
							data = result,
							code = "1",
							msg = "success"
						},
						JsonRequestBehavior.AllowGet);
					}
				}
				else
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "3",
						msg = ""
					},
					JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "2",
					msg = Resources.MsgSameMail
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取参会人列表
		public async Task<JsonResult> GetAttendeeByCreator(string uid, string conferenceId)
		{
			var user = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == uid);

			if (user != null)
			{
				var attendenceIdList = DbContext.ProfilePaymentRecord.AsNoTracking()
					.GroupBy(x => x.AttendenceId)
					.Select(x => new ProfileRecModel
					{
						AttendenceId = x.Key,
						Count = x.Count()
					}).ToList();

				var queryTemp = from a in DbContext.ProfilePaymentRecord.AsNoTracking()
						group a by a.AttendenceId into g
						select new { g.Key, g };

				var sql = from conferenceAttendenceInfo in DbContext.ConferenceAttendenceInfo.AsNoTracking()
						.Where(x => x.Creator == user.UserName && x.ConferenceId == conferenceId
							&& !(string.IsNullOrEmpty(x.FamilyName) && string.IsNullOrEmpty(x.FirstName)
							&& string.IsNullOrEmpty(x.FullName)))
					  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
					       on conferenceAttendenceInfo.ConferenceId equals conferenceMaster.ID
					  join tran in DbContext.TransferEvidenceMaster.AsNoTracking()
					       on conferenceAttendenceInfo.ID equals tran.AttendenceId into t1
					  from trane in t1.DefaultIfEmpty()
					  join record in queryTemp
					       on conferenceAttendenceInfo.ID equals record.Key into t2
					  from rec in t2.DefaultIfEmpty()
					  join conferencePaymentMaster in DbContext.ConferencePaymentMaster.AsNoTracking()
					      on conferenceAttendenceInfo.PaymentTypeId equals conferencePaymentMaster.ID into t3
					  from conferencePaymentMaster in t3.DefaultIfEmpty()
					  join sysPaymentMaster in DbContext.SysPaymentMaster.AsNoTracking()
						on conferencePaymentMaster.PayId equals sysPaymentMaster.ID into t4
					  from sysPaymentMaster in t4.DefaultIfEmpty()
					  select new
					  {
						  Id = conferenceAttendenceInfo.ID,
						  FamilyName = conferenceAttendenceInfo.FamilyName,
						  FirstName = conferenceAttendenceInfo.FirstName,
						  FullName = conferenceAttendenceInfo.FullName,
						  Mail = conferenceAttendenceInfo.Mail,
						  ConferenceId = conferenceAttendenceInfo.ConferenceId,
						  HasPaid = conferenceAttendenceInfo.HasPaid
					  };

				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.Id,
					FamilyName = string.IsNullOrEmpty(x.FamilyName) ? string.Empty : x.FamilyName,
					FirstName = string.IsNullOrEmpty(x.FirstName) ? string.Empty : x.FirstName,
					FullName = string.IsNullOrEmpty(x.FullName) ? string.Empty : x.FullName,
					Mail = string.IsNullOrEmpty(x.Mail) ? string.Empty : x.Mail,
					ConferenceId = x.ConferenceId,
					HasPaid = x.HasPaid ? "hasPaid" : "hasNotPaid"
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取全部报告列表
		public async Task<JsonCamelCaseResult> GetAllReports(string conferenceId, string topicId, string reportId)
		{
			if (conferenceId != null)
			{
				var sql = from contributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							(!string.IsNullOrEmpty(x.AdminStatus) ? x.AdminStatus == ConstValues.ContributationStatus.录用 :
								x.ContributationStatus == ConstValues.ContributationStatus.录用) &&
							x.EssayTitle != ConstValues.ChairmanReportCn &&
							x.EssayTitle != ConstValues.ChairmanReportEn)
					  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
						  on contributeInfo.ConferenceId equals conferenceMaster.ID
					  join reportMaster in DbContext.ReportMaster.AsNoTracking()
						  on contributeInfo.ReportId equals reportMaster.ID into t1
					  from report in t1.DefaultIfEmpty()
					  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
						  on contributeInfo.TopicId equals topicMaster.ID into t2
					  from topic in t2.DefaultIfEmpty()
					  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
						  on contributeInfo.ID equals authorInfo.ContributeId into t3
					  from author in t3.DefaultIfEmpty()
					  join scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
						  on contributeInfo.ID equals scheduleInfo.ContributeId into t4
					  from scheduleInf in t4.DefaultIfEmpty()
					  join scheduleMaster in DbContext.ScheduleMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
						  on scheduleInf.ScheduleId equals scheduleMaster.ID into t5
					  from scheduleMst in t5.DefaultIfEmpty()
					  where ((report.ReportType == ConstValues.PosterCn || report.ReportType == ConstValues.PosterEn) && contributeInfo.IsConfirm) ||
						    ((report.ReportType != ConstValues.PosterCn && report.ReportType != ConstValues.PosterEn) && scheduleInf.Status == ConstValues.ScheduleStatus.已安排)
					  orderby scheduleInf.ScheduleDate, scheduleInf.StartTime, scheduleInf.EndTime, topic.Sort
					  select new
					  {
						  Id = contributeInfo.ID,
						  TopicId = contributeInfo.TopicId,
						  TopicName = string.IsNullOrEmpty(contributeInfo.TopicId) ? string.Empty : topic.TopicName,
						  ReportId = contributeInfo.ReportId,
						  ReportType = string.IsNullOrEmpty(contributeInfo.ReportId) ? string.Empty : report.ReportType,
						  ProgramAbstract = contributeInfo.ProgramAbstract,
						  Abstract = contributeInfo.Abstract,
						  Keyword = contributeInfo.Keyword,
						  EssayTitle = contributeInfo.EssayTitle,
						  Presenter = author.FullName,
						  SelfIntroduction = author.SelfIntroduction,
						  //Affiliation = author.Affiliation,
						  Country = author.Country,
						  Mail = author.Mail,
						  ConferenceId = contributeInfo.ConferenceId,
						  FullName = author.FullName,
						  Status = contributeInfo.ScheduleStatus,
						  ScheduleId = scheduleInf == null ? string.Empty : scheduleInf.ID,
						  ScheduleDate = scheduleInf == null ? new DateTime() : scheduleInf.ScheduleDate,
						  StartTime = scheduleInf == null ? new TimeSpan(0) : scheduleInf.StartTime,
						  EndTime = scheduleInf == null ? new TimeSpan(0) : scheduleInf.EndTime,
						  Sort = contributeInfo.Sort,
						  CreateDate = contributeInfo.CreateDate,
						  SchedulePlace = scheduleMst == null ? string.Empty : scheduleMst.SchedulePlace,
						  ConferenceName = conferenceMaster.ConferenceName,
						  NickName = conferenceMaster.ConferenceNickName,
						  IsInternational = conferenceMaster.IsInternational,
						  IsContribute = scheduleInf == null ? false : scheduleInf.IsContribute
					  };

				if (!string.IsNullOrEmpty(topicId))
				{
					sql = sql.Where(x => x.TopicId == topicId);
				}

				if (!string.IsNullOrEmpty(reportId))
				{
					sql = sql.Where(x => x.ReportId == reportId);
				}

				sql.OrderBy(x => x.Sort).ThenBy(x => x.CreateDate);

				var sqlResult = await sql.ToListAsync();

				var result = new List<ConferenceScheduleReportModel>();
				sqlResult.ForEach(y =>
				{
					var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.ContributeId == y.Id &&
							x.Mail == y.Mail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => x.Affiliation)
						.ToList();
					var strAffiliation = affiliationList.Count > 0 ? string.Join(ConstValues.strSemicolon, affiliationList) : string.Empty;

					var authorList = DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ContributeId == y.Id &&
							x.ConferenceId == y.ConferenceId)
						.OrderBy(x => x.Sort)
						.Select(x => x.FullName);

					result.Add(new ConferenceScheduleReportModel()
					{
						Id = y.Id,
						ReportId = y.ReportId,
						TopicId = y.TopicId,
						ReportType = y.ReportType,
						TopicName = y.TopicName,
						ProgramAbstract = string.IsNullOrEmpty(y.ProgramAbstract) ?
								string.Empty : Utility.GetNoHtmlLeaveSubSup(y.ProgramAbstract),
						Abstract = string.IsNullOrEmpty(y.Abstract) ? string.Empty : Utility.GetNoHtmlLeaveSubSup(y.Abstract),
						Keyword = string.IsNullOrEmpty(y.Keyword) ? string.Empty : y.Keyword,
						EssayTitle = y.EssayTitle,
						FullName = string.IsNullOrEmpty(y.FullName) ? string.Empty : y.FullName,
						Country = y.Country == null ? string.Empty : DbContext.LocationMaster.FirstOrDefault(z => z.ID == y.Country)?.NameEn,
						Affiliation = string.IsNullOrEmpty(strAffiliation) ? string.Empty : strAffiliation,
						AffiliationAndCountry = y.IsInternational ?
								Utility.GetAllAffiliationEn(y.ConferenceId, y.Mail, y.Id, ConstValues.strComma) :
								Utility.GetAllAffiliation(y.ConferenceId, y.Mail, y.Id, ConstValues.strCommaCn),
						Author = authorList.ToList().Count > 0 ? string.Join(ConstValues.strSemicolon, authorList) : string.Empty,
						Presenter = string.IsNullOrEmpty(y.Presenter) ? string.Empty : y.Presenter,
						SelfIntroduction = string.IsNullOrEmpty(y.SelfIntroduction) ? string.Empty : y.SelfIntroduction,
						ScheduleTime = y.ScheduleDate == new DateTime() ? string.Empty : y.ScheduleDate.ToString("yyyy-MM-dd"),
						StartTime = y.StartTime == new TimeSpan(0) ? string.Empty : y.StartTime.ToString().Substring(0, 5),
						EndTime = y.EndTime == new TimeSpan(0) ? string.Empty : y.EndTime.ToString().Substring(0, 5),
						Status = y.Status,
						SchedulePlace = string.IsNullOrEmpty(y.SchedulePlace) ? string.Empty : y.SchedulePlace,
						ConferenceId = y.ConferenceId,
						ConferenceName = y.ConferenceName,
						IsContribute = y.IsContribute,
						ConferenceNickName = y.NickName,
						ScheduleId = y.ScheduleId
					});
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//取个人参会信息
		public async Task<JsonCamelCaseResult> GetAttendInfoById(string id)
		{
			var sql = from info in DbContext.ConferenceAttendenceInfo.AsNoTracking().Where(x => x.ID == id)
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.版面费)
					on info.ID equals profilePaymentInfo.AttendenceId into t1
				  from pageFee in t1.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.参会费)
					on info.ID equals profilePaymentInfo.AttendenceId into t2
				  from attendenceFee in t2.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.餐费)
					on info.ID equals profilePaymentInfo.AttendenceId into t3
				  from mealFee in t3.DefaultIfEmpty()
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
				       on info.ConferenceId equals conferenceMaster.ID
				  join invoiceMaster in DbContext.ConferenceInvoiceMaster.AsNoTracking()
				  on info.InvoiceId equals invoiceMaster.ID into t4
				  from invoice in t4.DefaultIfEmpty()
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  FamilyName = info.FamilyName,
					  FirstName = info.FirstName,
					  FullName = info.FullName,
					  Gender = info.Gender,
					  Title = info.Title,
					  Degree = info.Degree,
					  Job = info.Job,
					  Affiliation = info.Affiliation,
					  Department = info.Department,
					  CardId = info.CardId,
					  AttendenceIdentityId = info.AttendenceIdentityId,
					  EssayId = info.EssayId,
					  Mail = info.Mail,
					  Telephone = info.Telephone,
					  Mobile = info.Mobile,
					  Country = info.Country,
					  State = info.StateStr,
					  City = info.CityStr,
					  Address = info.Address,
					  ZipCode = info.ZipCode,
					  InvoiceTitle = info.InvoiceTitle,
					  TaxNum = info.TaxNum,
					  AddressAndTel = info.AddressAndTel,
					  Bank = info.Bank,
					  BankAccount = info.BankAccount,
					  InvoiceId = info.InvoiceId,
					  InvoiceDetail = invoice.InvoiceDetail,
					  PaymentTypeId = info.PaymentTypeId,
					  HotelId = info.HotelId,
					  RoomTypeId = info.RoomTypeId,
					  RoomCount = info.RoomCount,
					  BedCount = info.BedCount,
					  CheckinDate = info.CheckinDate,
					  CheckoutDate = info.CheckoutDate,
					  CheckinDaysCount = info.CheckinDaysCount,
					  HotelRemark = info.HotelRemark,
					  ArrivalDate = info.ArrivalDate,
					  ArrivalFlight = info.ArrivalFlight,
					  DeparturalDate = info.DeparturalDate,
					  DeparturalFlight = info.DeparturalFlight,
					  FavouriteTopicId = info.FavouriteTopicId,
					  Currency = info.Currency,
					  PageFeeId = pageFee.FeeId,
					  AttendenceFeeId = attendenceFee.FeeId,
					  MealFeeId = mealFee.FeeId,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  HasPaid = info.HasPaid,
					  IsInternational = conferenceMaster.IsInternational,
					  Customize1 = info.Customize1,
					  Customize2 = info.Customize2,
					  Customize3 = info.Customize3,
					  Customize4 = info.Customize4,
					  Customize5 = info.Customize5,

				  };

			var sqlResult = await sql.ToListAsync();

			var eventPaymentInfo = await DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.FeeType == ConstValues.FeeType.同期活动费 && x.AttendenceId == id)
					.ToListAsync();
			var ConcurrentEventList = "";
			var ConcurrentEventCount = "";
			var ConcurrentEventIdList = "";
			eventPaymentInfo.ForEach(x =>
			{
				if (ConcurrentEventList == "")
				{
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					ConcurrentEventList += DbContext.ConcurrentEventMaster.FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
					ConcurrentEventCount += x.Count.Value.ToString();
					ConcurrentEventIdList += ConcurrentEventId;
				}
				else
				{
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					ConcurrentEventList += ConstValues.chrComma + DbContext.ConcurrentEventMaster.FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
					ConcurrentEventCount += ConstValues.chrComma + x.Count.Value.ToString();
					ConcurrentEventIdList += ConstValues.chrComma + ConcurrentEventId;
				}
			});

			var otherPaymentInfo = await DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.FeeType == ConstValues.FeeType.其他费用 && x.AttendenceId == id)
					.ToListAsync();
			var otherFeeList = "";
			var otherFeeCount = "";
			var otherFeeId = "";
			otherPaymentInfo.ForEach(x =>
			{
				if (otherFeeList == "")
				{
					otherFeeList += DbContext.FeeOtherMaster.FirstOrDefault(y => y.ID == x.FeeId)?.FeeName;
					otherFeeCount += x.Count.Value.ToString();
					otherFeeId += x.FeeId;
				}
				else
				{
					otherFeeList += ConstValues.chrComma + DbContext.FeeOtherMaster.FirstOrDefault(y => y.ID == x.FeeId)?.FeeName;
					otherFeeCount += ConstValues.chrComma + x.Count.Value.ToString();
					otherFeeId += ConstValues.chrComma + x.FeeId;
				}
			});

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				ConferenceId = x.ConferenceId,
				FamilyName = x.FamilyName,
				FirstName = x.FirstName,
				FullName = x.FullName,
				Gender = x.Gender.ToString(),
				TitleId = x.Title,
				TitleName = DbContext.TitleMaster.FirstOrDefault(y => y.ID == x.Title)?.TitleName,
				Degree = x.Degree,
				DegreeName = x.IsInternational ?
						DbContext.DegreeMaster.FirstOrDefault(y => y.ID == x.Degree)?.DegreeNameEn :
						DbContext.DegreeMaster.FirstOrDefault(y => y.ID == x.Degree)?.DegreeName,
				Job = x.Job,
				Affiliation = x.Affiliation,
				Department = x.Department,
				CardId = x.CardId,
				AttendenceIdentityId = x.AttendenceIdentityId,
				AttendenceIdentityName = DbContext.AttendenceIdentityMaster.FirstOrDefault(y => y.ID == x.AttendenceIdentityId)?.IdentityName,
				//Essay = x.EssayId.Split(ConstValues.chrSemicolon),
				Mail = x.Mail,
				Telephone = x.Telephone,
				Mobile = x.Mobile,
				Country = x.Country,
				CountryName = x.IsInternational ?
							DbContext.LocationMaster.FirstOrDefault(y => y.ID == x.Country)?.NameEn :
							DbContext.LocationMaster.FirstOrDefault(y => y.ID == x.Country)?.Name,
				State = x.State,
				StateName = x.State,
				City = x.City,
				CityName = x.City,
				Address = x.Address,
				ZipCode = x.ZipCode,
				InvoiceTitle = x.InvoiceTitle,
				TaxNum = x.TaxNum,
				AddressAndTel = x.AddressAndTel,
				Bank = x.Bank,
				BankAccount = x.BankAccount,
				InvoiceId = x.InvoiceId,
				InvoiceDetail = x.InvoiceDetail,
				PaymentTypeId = x.PaymentTypeId,
				PaymentTypeName = DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId) != null ?
										(x.IsInternational ?
										DbContext.SysPaymentMaster.FirstOrDefault(z => z.ID == DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId).PayId).PaymentNameEn :
										DbContext.SysPaymentMaster.FirstOrDefault(z => z.ID == DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId).PayId).PaymentName)
								   : string.Empty,
				Currency = x.Currency,
				PageFeeId = x.PageFeeId,
				PageFeeName = DbContext.FeePageMaster.FirstOrDefault(y => y.ID == x.PageFeeId)?.FeeName,
				AttendenceFeeId = x.AttendenceFeeId,
				AttendenceFeeName = DbContext.FeeAttendenceMaster.FirstOrDefault(y => y.ID == x.AttendenceFeeId)?.RegisterType,
				MealFeeId = x.MealFeeId,
				MealFeeName = DbContext.FeeMealMaster.FirstOrDefault(y => y.ID == x.MealFeeId)?.FeeName,
				Sort = x.Sort,
				Remark = x.Remark,
				HasPaid = x.HasPaid,
				ConcurrentEventList = ConcurrentEventList,
				ConcurrentEventCount = ConcurrentEventCount,
				ConcurrentEventId = ConcurrentEventIdList,
				otherFeeList = otherFeeList,
				otherFeeCount = otherFeeCount,
				otherFeeId = otherFeeId,
				applyIdentity = Utility.GetApplyIdentity(id),
				FavouriteTopic = ChangeFavouriteTopicIdToName(x.FavouriteTopicId),
				FavouriteTopicId = x.FavouriteTopicId,
				Customize1 = x.Customize1,
				Customize2 = x.Customize2,
				Customize3 = x.Customize3,
				Customize4 = x.Customize4,
				Customize5 = x.Customize5,
			});

			if (result.Count() > 0)
			{
				return JsonCamelCase(new
				{
					data = result.First(),
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//取个人参会信息IOS
		public async Task<JsonCamelCaseResult> GetAttendInfoByIdIOS(string id)
		{
			var sql = from info in DbContext.ConferenceAttendenceInfo.AsNoTracking().Where(x => x.ID == id)
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.版面费)
					on info.ID equals profilePaymentInfo.AttendenceId into t1
				  from pageFee in t1.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.参会费)
					on info.ID equals profilePaymentInfo.AttendenceId into t2
				  from attendenceFee in t2.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.餐费)
					on info.ID equals profilePaymentInfo.AttendenceId into t3
				  from mealFee in t3.DefaultIfEmpty()
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
				       on info.ConferenceId equals conferenceMaster.ID
				  join invoiceMaster in DbContext.ConferenceInvoiceMaster.AsNoTracking()
				  on info.InvoiceId equals invoiceMaster.ID into t4
				  from invoice in t4.DefaultIfEmpty()
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  FamilyName = info.FamilyName,
					  FirstName = info.FirstName,
					  FullName = info.FullName,
					  Gender = info.Gender,
					  Title = info.Title,
					  Degree = info.Degree,
					  Job = info.Job,
					  Affiliation = info.Affiliation,
					  Department = info.Department,
					  CardId = info.CardId,
					  AttendenceIdentityId = info.AttendenceIdentityId,
					  EssayId = info.EssayId,
					  Mail = info.Mail,
					  Telephone = info.Telephone,
					  Mobile = info.Mobile,
					  Country = info.Country,
					  State = info.StateStr,
					  City = info.CityStr,
					  Address = info.Address,
					  ZipCode = info.ZipCode,
					  InvoiceTitle = info.InvoiceTitle,
					  TaxNum = info.TaxNum,
					  AddressAndTel = info.AddressAndTel,
					  Bank = info.Bank,
					  BankAccount = info.BankAccount,
					  InvoiceId = info.InvoiceId,
					  InvoiceDetail = invoice.InvoiceDetail,
					  PaymentTypeId = info.PaymentTypeId,
					  HotelId = info.HotelId,
					  RoomTypeId = info.RoomTypeId,
					  RoomCount = info.RoomCount,
					  BedCount = info.BedCount,
					  CheckinDate = info.CheckinDate,
					  CheckoutDate = info.CheckoutDate,
					  CheckinDaysCount = info.CheckinDaysCount,
					  HotelRemark = info.HotelRemark,
					  ArrivalDate = info.ArrivalDate,
					  ArrivalFlight = info.ArrivalFlight,
					  DeparturalDate = info.DeparturalDate,
					  DeparturalFlight = info.DeparturalFlight,
					  FavouriteTopicId = info.FavouriteTopicId,
					  Currency = info.Currency,
					  PageFeeId = pageFee.FeeId,
					  AttendenceFeeId = attendenceFee.FeeId,
					  MealFeeId = mealFee.FeeId,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  HasPaid = info.HasPaid,
					  IsInternational = conferenceMaster.IsInternational,
					  Customize1 = info.Customize1,
					  Customize2 = info.Customize2,
					  Customize3 = info.Customize3,
					  Customize4 = info.Customize4,
					  Customize5 = info.Customize5,
				  };

			var sqlResult = await sql.ToListAsync();

			var eventPaymentInfo = await DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.FeeType == ConstValues.FeeType.同期活动费 && x.AttendenceId == id)
					.ToListAsync();
			var ConcurrentEventList = "";
			var ConcurrentEventCount = "";
			var ConcurrentEventIdList = "";
			eventPaymentInfo.ForEach(x =>
			{
				if (ConcurrentEventList == "")
				{
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					ConcurrentEventList += DbContext.ConcurrentEventMaster.FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
					ConcurrentEventCount += x.Count.Value.ToString();
					ConcurrentEventIdList += ConcurrentEventId;
				}
				else
				{
					var ConcurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
					ConcurrentEventList += ConstValues.chrComma + DbContext.ConcurrentEventMaster.FirstOrDefault(y => y.ID == ConcurrentEventId)?.EventName;
					ConcurrentEventCount += ConstValues.chrComma + x.Count.Value.ToString();
					ConcurrentEventIdList += ConstValues.chrComma + ConcurrentEventId;
				}
			});

			var otherPaymentInfo = await DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.FeeType == ConstValues.FeeType.其他费用 && x.AttendenceId == id)
					.ToListAsync();
			var otherFeeList = "";
			var otherFeeCount = "";
			var otherFeeId = "";
			otherPaymentInfo.ForEach(x =>
			{
				if (otherFeeList == "")
				{
					otherFeeList += DbContext.FeeOtherMaster.FirstOrDefault(y => y.ID == x.FeeId)?.FeeName;
					otherFeeCount += x.Count.Value.ToString();
					otherFeeId += x.FeeId;
				}
				else
				{
					otherFeeList += ConstValues.chrComma + DbContext.FeeOtherMaster.FirstOrDefault(y => y.ID == x.FeeId)?.FeeName;
					otherFeeCount += ConstValues.chrComma + x.Count.Value.ToString();
					otherFeeId += ConstValues.chrComma + x.FeeId;
				}
			});

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				ConferenceId = x.ConferenceId,
				FamilyName = string.IsNullOrEmpty(x.FamilyName) ? string.Empty : x.FamilyName,
				FirstName = string.IsNullOrEmpty(x.FirstName) ? string.Empty : x.FirstName,
				FullName = string.IsNullOrEmpty(x.FullName) ? string.Empty : x.FullName,
				Gender = x.Gender.ToString(),
				TitleId = string.IsNullOrEmpty(x.Title) ? string.Empty : x.Title,
				TitleName = string.IsNullOrEmpty(x.Title) ? string.Empty : DbContext.TitleMaster.FirstOrDefault(y => y.ID == x.Title)?.TitleName,
				Degree = x.Degree == null ? 0 : x.Degree,
				DegreeName = x.Degree == null ? string.Empty :
						(x.IsInternational ?
						DbContext.DegreeMaster.FirstOrDefault(y => y.ID == x.Degree)?.DegreeNameEn :
						DbContext.DegreeMaster.FirstOrDefault(y => y.ID == x.Degree)?.DegreeName),
				Job = string.IsNullOrEmpty(x.Job) ? string.Empty : x.Job,
				Affiliation = string.IsNullOrEmpty(x.Affiliation) ? string.Empty : x.Affiliation,
				Department = string.IsNullOrEmpty(x.Department) ? string.Empty : x.Department,
				CardId = string.IsNullOrEmpty(x.CardId) ? string.Empty : x.CardId,
				AttendenceIdentityId = string.IsNullOrEmpty(x.AttendenceIdentityId) ? string.Empty : x.AttendenceIdentityId,
				AttendenceIdentityName = string.IsNullOrEmpty(x.AttendenceIdentityId) ? string.Empty :
									DbContext.AttendenceIdentityMaster.FirstOrDefault(y => y.ID == x.AttendenceIdentityId)?.IdentityName,
				//Essay = x.EssayId.Split(ConstValues.chrSemicolon),
				Mail = string.IsNullOrEmpty(x.Mail) ? string.Empty : x.Mail,
				Telephone = string.IsNullOrEmpty(x.Telephone) ? string.Empty : x.Telephone,
				Mobile = string.IsNullOrEmpty(x.Mobile) ? string.Empty : x.Mobile,
				Country = x.Country == null ? 0 : x.Country,
				CountryName = x.Country == null ? string.Empty :
							(x.IsInternational ?
							DbContext.LocationMaster.FirstOrDefault(y => y.ID == x.Country)?.NameEn :
							DbContext.LocationMaster.FirstOrDefault(y => y.ID == x.Country)?.Name),
				State = x.State,
				StateName = x.State,
				City = x.City,
				CityName = x.City,
				Address = string.IsNullOrEmpty(x.Address) ? string.Empty : x.Address,
				ZipCode = string.IsNullOrEmpty(x.ZipCode) ? string.Empty : x.ZipCode,
				InvoiceTitle = string.IsNullOrEmpty(x.InvoiceTitle) ? string.Empty : x.InvoiceTitle,
				TaxNum = string.IsNullOrEmpty(x.TaxNum) ? string.Empty : x.TaxNum,
				AddressAndTel = string.IsNullOrEmpty(x.AddressAndTel) ? string.Empty : x.AddressAndTel,
				Bank = string.IsNullOrEmpty(x.Bank) ? string.Empty : x.Bank,
				BankAccount = string.IsNullOrEmpty(x.BankAccount) ? string.Empty : x.BankAccount,
				InvoiceId = string.IsNullOrEmpty(x.InvoiceId) ? string.Empty : x.InvoiceId,
				InvoiceDetail = string.IsNullOrEmpty(x.InvoiceDetail) ? string.Empty : x.InvoiceDetail,
				PaymentTypeId = string.IsNullOrEmpty(x.PaymentTypeId) ? string.Empty : x.PaymentTypeId,
				PaymentTypeName = DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId) != null ?
										(x.IsInternational ?
										DbContext.SysPaymentMaster.FirstOrDefault(z => z.ID == DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId).PayId).PaymentNameEn :
										DbContext.SysPaymentMaster.FirstOrDefault(z => z.ID == DbContext.ConferencePaymentMaster.FirstOrDefault(y => y.ID == x.PaymentTypeId).PayId).PaymentName)
								   : string.Empty,
				Currency = string.IsNullOrEmpty(x.Currency) ? string.Empty : x.Currency,
				PageFeeId = string.IsNullOrEmpty(x.PageFeeId) ? string.Empty : x.PageFeeId,
				PageFeeName = string.IsNullOrEmpty(x.PageFeeId) ? string.Empty :
								DbContext.FeePageMaster.FirstOrDefault(y => y.ID == x.PageFeeId)?.FeeName,
				AttendenceFeeId = string.IsNullOrEmpty(x.AttendenceFeeId) ? string.Empty : x.AttendenceFeeId,
				AttendenceFeeName = string.IsNullOrEmpty(x.AttendenceFeeId) ? string.Empty :
								DbContext.FeeAttendenceMaster.FirstOrDefault(y => y.ID == x.AttendenceFeeId)?.RegisterType,
				MealFeeId = string.IsNullOrEmpty(x.MealFeeId) ? string.Empty : x.MealFeeId,
				MealFeeName = string.IsNullOrEmpty(x.MealFeeId) ? string.Empty :
								DbContext.FeeMealMaster.FirstOrDefault(y => y.ID == x.MealFeeId)?.FeeName,
				Sort = x.Sort,
				Remark = string.IsNullOrEmpty(x.Remark) ? string.Empty : x.Remark,
				HasPaid = x.HasPaid,
				ConcurrentEventList = ConcurrentEventList,
				ConcurrentEventCount = ConcurrentEventCount,
				ConcurrentEventId = ConcurrentEventIdList,
				otherFeeList = otherFeeList,
				otherFeeCount = otherFeeCount,
				otherFeeId = otherFeeId,
				applyIdentity = Utility.GetApplyIdentity(id),
				FavouriteTopic = string.IsNullOrEmpty(x.FavouriteTopicId) ? string.Empty : ChangeFavouriteTopicIdToName(x.FavouriteTopicId),
				FavouriteTopicId = string.IsNullOrEmpty(x.FavouriteTopicId) ? string.Empty : x.FavouriteTopicId,
				Customize1 = string.IsNullOrEmpty(x.Customize1) ? string.Empty : x.Customize1,
				Customize2 = string.IsNullOrEmpty(x.Customize2) ? string.Empty : x.Customize2,
				Customize3 = string.IsNullOrEmpty(x.Customize3) ? string.Empty : x.Customize3,
				Customize4 = string.IsNullOrEmpty(x.Customize4) ? string.Empty : x.Customize4,
				Customize5 = string.IsNullOrEmpty(x.Customize5) ? string.Empty : x.Customize5,
			});

			if (result.Count() > 0)
			{
				return JsonCamelCase(new
				{
					data = result.First(),
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//会议管理
		public async Task<JsonCamelCaseResult> GetManageConference(string uid)
		{
			var sql = DbContext.ConferenceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常);

			var user = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == uid);

			if (user != null)
			{
				var username = user.UserName;

				var matchSSA = await DbContext.ViewUserRoleAction.AsNoTracking()
						.FirstOrDefaultAsync(x => x.UserName == username && x.RoleName == ConstValues.SA);

				if (matchSSA == null)
				{
					var conferenceIDList = await DbContext.ViewConferenceRoleAction.AsNoTracking()
						.Where(x => x.UserName == username &&
								(x.RoleName == ConstValues.CA ||
								 (x.FunctionID == ConstValues.FunctionId.ConferenceContributeInfo &&
								 x.Modify == 1)))
						.Select(x => x.ConferenceID)
						.ToListAsync();

					sql = sql.Where(x => conferenceIDList.Contains(x.ID) || x.Creator == username);
				}

				sql = sql.OrderBy(x => x.Sort).ThenByDescending(x => x.ConferenceStartDate);

				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					ConferenceName = x.ConferenceName,
					OperateTime = x.OperateTime,
					ConferenceStartDate = x.ConferenceStartDate.Value.ToString("yyyy-MM-dd"),
					ConferenceEndDate = x.ConferenceEndDate.Value.ToString("yyyy-MM-dd"),
					OperateLocation = x.OperateLocation,
					HomePageUrl = x.HomePageUrl,
					CreateTime = x.CreateDate.Value.ToString("yyyy-MM-dd HH:mm"),
					Status = x.Status,
					ConferenceNickName = x.ConferenceNickName,
					IsInHome = x.IsInHome ? Resources.Yes : Resources.No,
					IsRecommend = x.IsRecommend ? Resources.Yes : Resources.No,
					IsDisplay = x.IsDisplay ? Resources.Yes : Resources.No,
					IsInternational = x.IsInternational
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//作者 by 稿件ID
		public async Task<JsonCamelCaseResult> GetAuthorByContributeId(string contributeId)
		{

			var sql = DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ContributeId == contributeId)
						.OrderBy(x => x.Sort);

			var sqlResult = await sql.ToListAsync();

			if (sqlResult.Count > 0)
			{
				var result = sqlResult.Select(x => new
				{
					FullName = x.FullName,
					Mail = x.Mail == null ? string.Empty : x.Mail,
					Mobile = x.Mobile == null ? string.Empty : x.Mobile,
					IsFirstAuthor = x.IsFirstAuthor,
					IsPresenter = x.IsPresenter,
					IsContactAuthor = x.IsContactAuthor,
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//会议管理 -- 出席情况录入
		public async Task<JsonCamelCaseResult> submitRecord(string contributeId, string attendance, string description, string summary)
		{

			var authorInfo = await DbContext.AuthorInfo.FirstOrDefaultAsync(x => x.ContributeId == contributeId && x.IsPresenter == true);

			if (authorInfo != null)
			{

				authorInfo.Attendance = attendance;
				authorInfo.Description = description;
				authorInfo.Summary = summary;

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(new
				{
					data = "",
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);

			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//会议管理 -- 出席情况录入IOS
		public async Task<JsonCamelCaseResult> submitRecordIOS(SubmitRecordIOSModel model)
		{
			var contributeId = model.contributeId;
			var attendance = model.attendance;
			var description = model.description;
			var summary = model.summary;

			var authorInfo = await DbContext.AuthorInfo.FirstOrDefaultAsync(x => x.ContributeId == contributeId && x.IsPresenter == true);

			if (authorInfo != null)
			{

				authorInfo.Attendance = attendance;
				authorInfo.Description = description;
				authorInfo.Summary = summary;

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(new
				{
					data = "",
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);

			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//会议管理 -- 出席情况获取
		public async Task<JsonCamelCaseResult> GetAttendanceRecord(string contributeId)
		{

			var authorInfo = await DbContext.AuthorInfo.AsNoTracking().FirstOrDefaultAsync(x => x.ContributeId == contributeId && x.IsPresenter == true);

			if (authorInfo != null)
			{

				var result = new
				{
					Attendance = authorInfo.Attendance == null ? string.Empty : authorInfo.Attendance,
					Description = authorInfo.Description == null ? string.Empty : authorInfo.Description,
					Summary = authorInfo.Summary == null ? string.Empty : authorInfo.Summary
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//手机端修改参会注册信息
		//flag是字段名
		//str1是第一个参数，是用户填的参数
		//str2是第二个参数，只有同期活动、其他费用、参会身份、省才有这个参数，其他情况下这个参数都为空
		//str3是第三个参数，只有市和同期活动用到的参会身份
		//str4是第四个参数，只有同期活动用到的币种
		//userName是修改者的userName
		//ip是手机ip
		public async Task<JsonCamelCaseResult> ModifyAttendenceInfo(string flag, string str1, string str2, string str3, string str4, string userName, string ip, string attendId)
		{
			var result = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);
			if (result == null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = Resources.MsgRecordNotExist
				},
				JsonRequestBehavior.AllowGet);
			}
			str1 = string.IsNullOrEmpty(str1) ? string.Empty : str1.Replace("~", " ");
			str2 = string.IsNullOrEmpty(str2) ? string.Empty : str2.Replace("~", " ");
			userName = userName.Replace("~", " ");
			using (var transaction = DbContext.Database.BeginTransaction())
			{
				switch (flag)
				{
					case "familyName":
						result.FamilyName = str1.Trim();
						break;
					case "firstName":
						result.FirstName = str1.Trim();
						break;
					case "fullName":
						result.FullName = str1.Trim();
						break;
					case "gender":
						var gender = (str1 == "男" || str1 == "Male") ? true : false;
						result.Gender = gender;
						break;
					case "title":
						result.Title = str1;
						break;
					case "education":
						var degreeMaster = DbContext.DegreeMaster.FirstOrDefault(x => x.DegreeName == str1 || x.DegreeNameEn == str1);
						if (degreeMaster != null)
						{
							result.Degree = degreeMaster.ID;
						}
						break;
					case "job":
						result.Job = str1.Trim();
						break;
					case "affiliation":
						result.Affiliation = str1.Trim();
						break;
					case "department":
						result.Department = str1.Trim();
						break;
					case "country":
						var countryMaster = DbContext.LocationMaster.FirstOrDefault(x => x.Name == str1 || x.NameEn == str1);
						if (countryMaster != null)
						{
							result.Country = countryMaster.ID;
						}
						else
						{
							result.Country = null;
						}
						break;
					case "state":
						result.StateStr = str1.Trim();
						break;
					case "city":
						result.CityStr = str1.Trim();
						break;
					case "address":
						result.Address = str1.Trim();
						break;
					case "zipcode":
						result.ZipCode = str1.Trim();
						break;
					case "tel":
						result.Telephone = str1.Trim();
						break;
					case "mobile":
						result.Mobile = str1.Trim();
						break;
					case "idcard":
						result.CardId = str1.Trim();
						break;
					case "attendidentity":
						result.AttendenceIdentityId = str1;

						if (str2 == "true")
						{
							//清空同期活动
							var profilePaymentInfo = DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToList();
							profilePaymentInfo.ForEach(x =>
							{
								result.TotalFee -= x.Fee;
								result.Discount -= x.Discount;
							});
							DbContext.ProfilePaymentInfo.RemoveRange(profilePaymentInfo);
						}
						else if (str2 == "false")
						{
							var profilePaymentInfo = DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToList();
							profilePaymentInfo.ForEach(x =>
							{
								result.TotalFee -= x.Fee;
								result.Discount -= x.Discount;

								var concurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
								if (!string.IsNullOrEmpty(concurrentEventId))
								{
									var feeConcurrentEventMaster = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ConcurrentEventId == concurrentEventId &&
												 (y.AttendenceIdentityId == ConstValues.ApplicableForAll || y.AttendenceIdentityId == str1));
									if (feeConcurrentEventMaster != null)
									{
										x.Fee = feeConcurrentEventMaster.Price.Value * x.Count.Value;
										x.Discount = feeConcurrentEventMaster.Price.Value * x.Count.Value;

										result.TotalFee += feeConcurrentEventMaster.Price.Value * x.Count.Value;
										result.Discount += feeConcurrentEventMaster.Price.Value * x.Count.Value;
									}
								}
							});
						}
						break;
					case "attendenceFee":
						var paymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.参会费);
						if (paymentInfo != null)
						{
							result.TotalFee -= paymentInfo.Fee;
							result.Discount -= paymentInfo.Discount;
							DbContext.ProfilePaymentInfo.Remove(paymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.参会费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "pageFee":
						var pagePaymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.版面费);
						if (pagePaymentInfo != null)
						{
							result.TotalFee -= pagePaymentInfo.Fee;
							result.Discount -= pagePaymentInfo.Discount;
							result.HasPage = false;
							DbContext.ProfilePaymentInfo.Remove(pagePaymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeePageMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.版面费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.HasPage = true;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "mealFee":
						var mealPaymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.餐费);
						if (mealPaymentInfo != null)
						{
							result.TotalFee -= mealPaymentInfo.Fee;
							result.Discount -= mealPaymentInfo.Discount;
							result.HasMeal = false;
							DbContext.ProfilePaymentInfo.Remove(mealPaymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.餐费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.HasMeal = true;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "other":
						var oldOtherFee = await DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.其他费用).ToListAsync();
						if (oldOtherFee.Count > 0)
						{
							for (var i = 0; i < oldOtherFee.Count; i++)
							{
								result.TotalFee -= oldOtherFee[i].Fee;
								result.Discount -= oldOtherFee[i].Fee;
							}

							DbContext.ProfilePaymentInfo.RemoveRange(oldOtherFee);
						}
						if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
						{
							var otherFee = str1.Split(ConstValues.chrComma);
							var otherFeeCount = str2.Split(ConstValues.chrComma);
							for (var index = 0; index < otherFee.Length; index++)
							{
								string tmp = otherFee[index];
								int count = int.Parse(otherFeeCount[index]);

								var feeMaster = DbContext.FeeOtherMaster.AsNoTracking().FirstOrDefault(x => x.ID == tmp && x.Status == ConstValues.Status.正常);

								if (feeMaster != null && count != 0)
								{
									var profilePaymentInfo = new ProfilePaymentInfo
									{
										ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
										UserName = userName,
										AttendenceId = attendId,
										FeeType = ConstValues.FeeType.其他费用,
										FeeId = feeMaster.ID,
										Count = count,
										Fee = feeMaster.Price.Value * count,
										Discount = feeMaster.Price.Value * count,
										Currency = feeMaster.Currency,
										Creator = userName,
										CreateIP = ip,
										CreateDate = DateTime.Now
									};

									DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

									result.TotalFee += feeMaster.Price.Value * count;
									result.Discount += feeMaster.Price.Value * count;
									result.Currency = feeMaster.Currency;
								}
							}
						}
						break;
					case "invoicetitle":
						result.InvoiceTitle = str1.Trim();
						break;
					case "taxnum":
						result.TaxNum = str1.Trim();
						break;
					case "addressAndTel":
						result.AddressAndTel = str1.Trim();
						break;
					case "bank":
						result.Bank = str1.Trim();
						break;
					case "bankAccount":
						result.BankAccount = str1.Trim();
						break;
					case "invoiceDetail":
						result.InvoiceId = str1;
						break;
					case "favouriteTopic":
						result.FavouriteTopicId = str1.Trim();
						break;
					case "customize1":
						result.Customize1 = str1.Trim();
						break;
					case "customize2":
						result.Customize2 = str1.Trim();
						break;
					case "customize3":
						result.Customize3 = str1.Trim();
						break;
					case "customize4":
						result.Customize4 = str1.Trim();
						break;
					case "customize5":
						result.Customize5 = str1.Trim();
						break;
					case "concurrentEvent":
						var eventFee = await DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToListAsync();
						if (eventFee.Count > 0)
						{
							for (var i = 0; i < eventFee.Count; i++)
							{
								result.TotalFee -= eventFee[i].Fee;
								result.Discount -= eventFee[i].Fee;
							}

							DbContext.ProfilePaymentInfo.RemoveRange(eventFee);
						}
						if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
						{
							var concurrentEventList = str1.Split(ConstValues.chrComma);
							var concurrentEventCount = str2.Split(ConstValues.chrComma);
							for (var index = 0; index < concurrentEventList.Length; index++)
							{
								string tmp = concurrentEventList[index];
								int count = int.Parse(concurrentEventCount[index]);

								var feeMaster = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(x => x.ConcurrentEventId == tmp && x.Status == ConstValues.Status.正常
											&& (x.AttendenceIdentityId == str3 || x.AttendenceIdentityId == ConstValues.ApplicableForAll)
											&& x.Currency == str4);

								if (feeMaster != null && count != 0)
								{
									var profilePaymentInfo = new ProfilePaymentInfo
									{
										ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
										UserName = userName,
										AttendenceId = attendId,
										FeeType = ConstValues.FeeType.同期活动费,
										FeeId = feeMaster.ID,
										Count = count,
										Fee = feeMaster.Price.Value * count,
										Discount = feeMaster.Price.Value * count,
										Currency = feeMaster.Currency,
										Creator = userName,
										CreateIP = ip,
										CreateDate = DateTime.Now
									};

									DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

									result.TotalFee += feeMaster.Price.Value * count;
									result.Discount += feeMaster.Price.Value * count;
									result.Currency = feeMaster.Currency;
								}
							}
						}
						break;
					case "payType":
						result.PaymentTypeId = str1;
						break;
					default:
						break;

				}
				result.UpdateDate = DateTime.Now;
				result.UpdateIP = ip;
				result.Updater = userName;

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//手机端修改参会注册信息
		//flag是字段名
		//str1是第一个参数，是用户填的参数
		//str2是第二个参数，只有同期活动、其他费用、参会身份、省才有这个参数，其他情况下这个参数都为空
		//str3是第三个参数，只有市和同期活动用到的参会身份
		//str4是第四个参数，只有同期活动用到的币种
		//userName是修改者的userName
		//ip是手机ip
		public async Task<JsonCamelCaseResult> ModifyAttendenceInfoIOS(MeetingAttendIOSModifyModel model)
		{
			var flag = model.flag;
			var str1 = model.str1;
			var str2 = model.str2;
			var str3 = model.str3;
			var str4 = model.str4;
			var userName = model.userName;
			var ip = model.ip;
			var attendId = model.attendId;

			var result = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == attendId);
			if (result == null)
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = Resources.MsgRecordNotExist
				},
				JsonRequestBehavior.AllowGet);
			}
			str1 = string.IsNullOrEmpty(str1) ? string.Empty : str1.Replace("~", " ");
			str2 = string.IsNullOrEmpty(str2) ? string.Empty : str2.Replace("~", " ");
			userName = userName.Replace("~", " ");
			using (var transaction = DbContext.Database.BeginTransaction())
			{
				switch (flag)
				{
					case "familyName":
						result.FamilyName = str1.Trim();
						break;
					case "firstName":
						result.FirstName = str1.Trim();
						break;
					case "fullName":
						result.FullName = str1.Trim();
						break;
					case "gender":
						var gender = (str1 == "男" || str1 == "Male") ? true : false;
						result.Gender = gender;
						break;
					case "title":
						result.Title = str1;
						break;
					case "education":
						var degreeMaster = DbContext.DegreeMaster.FirstOrDefault(x => x.DegreeName == str1 || x.DegreeNameEn == str1);
						if (degreeMaster != null)
						{
							result.Degree = degreeMaster.ID;
						}
						break;
					case "job":
						result.Job = str1.Trim();
						break;
					case "affiliation":
						result.Affiliation = str1.Trim();
						break;
					case "department":
						result.Department = str1.Trim();
						break;
					case "country":
						var countryMaster = DbContext.LocationMaster.FirstOrDefault(x => x.Name == str1 || x.NameEn == str1);
						if (countryMaster != null)
						{
							result.Country = countryMaster.ID;
						}
						else
						{
							result.Country = null;
						}
						break;
					case "state":
						result.StateStr = str1.Trim();
						break;
					case "city":
						result.CityStr = str1.Trim();
						break;
					case "address":
						result.Address = str1.Trim();
						break;
					case "zipcode":
						result.ZipCode = str1.Trim();
						break;
					case "tel":
						result.Telephone = str1.Trim();
						break;
					case "mobile":
						result.Mobile = str1.Trim();
						break;
					case "idcard":
						result.CardId = str1.Trim();
						break;
					case "attendidentity":
						result.AttendenceIdentityId = str1;
						if (str2 == "true")
						{
							//清空同期活动
							var profilePaymentInfo = DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToList();
							profilePaymentInfo.ForEach(x =>
							{
								result.TotalFee -= x.Fee;
								result.Discount -= x.Discount;
							});
							DbContext.ProfilePaymentInfo.RemoveRange(profilePaymentInfo);
						}
						else if (str2 == "false")
						{
							var profilePaymentInfo = DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToList();
							profilePaymentInfo.ForEach(x =>
							{
								result.TotalFee -= x.Fee;
								result.Discount -= x.Discount;

								var concurrentEventId = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ID == x.FeeId)?.ConcurrentEventId;
								if (!string.IsNullOrEmpty(concurrentEventId))
								{
									var feeConcurrentEventMaster = DbContext.FeeConcurrentEventMaster.FirstOrDefault(y => y.ConcurrentEventId == concurrentEventId &&
												 (y.AttendenceIdentityId == ConstValues.ApplicableForAll || y.AttendenceIdentityId == str1));
									if (feeConcurrentEventMaster != null)
									{
										x.Fee = feeConcurrentEventMaster.Price.Value * x.Count.Value;
										x.Discount = feeConcurrentEventMaster.Price.Value * x.Count.Value;

										result.TotalFee += feeConcurrentEventMaster.Price.Value * x.Count.Value;
										result.Discount += feeConcurrentEventMaster.Price.Value * x.Count.Value;
									}
								}
							});
						}
						break;
					case "attendenceFee":
						var paymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.参会费);
						if (paymentInfo != null)
						{
							result.TotalFee -= paymentInfo.Fee;
							result.Discount -= paymentInfo.Discount;
							DbContext.ProfilePaymentInfo.Remove(paymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.参会费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "pageFee":
						var pagePaymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.版面费);
						if (pagePaymentInfo != null)
						{
							result.TotalFee -= pagePaymentInfo.Fee;
							result.Discount -= pagePaymentInfo.Discount;
							result.HasPage = false;
							DbContext.ProfilePaymentInfo.Remove(pagePaymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeePageMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.版面费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.HasPage = true;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "mealFee":
						var mealPaymentInfo = DbContext.ProfilePaymentInfo.FirstOrDefault(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.餐费);
						if (mealPaymentInfo != null)
						{
							result.TotalFee -= mealPaymentInfo.Fee;
							result.Discount -= mealPaymentInfo.Discount;
							result.HasMeal = false;
							DbContext.ProfilePaymentInfo.Remove(mealPaymentInfo);
						}

						if (!string.IsNullOrEmpty(str1))
						{
							var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
									.FirstOrDefault(x => x.ID == str1);
							if (feeMaster != null && feeMaster.Price.HasValue)
							{
								double originFee = feeMaster.Price.Value;
								double discountFee = feeMaster.Price.Value;

								var profilePaymentInfo = new ProfilePaymentInfo
								{
									ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
									UserName = userName,
									AttendenceId = attendId,
									FeeType = ConstValues.FeeType.餐费,
									FeeId = str1,
									Count = 1,
									Fee = originFee,
									Discount = discountFee,
									Currency = feeMaster.Currency,
									Creator = userName,
									CreateIP = ip,
									CreateDate = DateTime.Now
								};

								DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

								result.TotalFee += originFee;
								result.Discount += discountFee;
								result.HasMeal = true;
								result.Currency = feeMaster.Currency;
							}
						}
						break;
					case "other":
						var oldOtherFee = await DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.其他费用).ToListAsync();
						if (oldOtherFee.Count > 0)
						{
							for (var i = 0; i < oldOtherFee.Count; i++)
							{
								result.TotalFee -= oldOtherFee[i].Fee;
								result.Discount -= oldOtherFee[i].Fee;
							}

							DbContext.ProfilePaymentInfo.RemoveRange(oldOtherFee);

						}
						if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
						{
							var otherFee = str1.Split(ConstValues.chrComma);
							var otherFeeCount = str2.Split(ConstValues.chrComma);
							for (var index = 0; index < otherFee.Length; index++)
							{
								string tmp = otherFee[index];
								int count = int.Parse(otherFeeCount[index]);

								var feeMaster = DbContext.FeeOtherMaster.AsNoTracking().FirstOrDefault(x => x.ID == tmp && x.Status == ConstValues.Status.正常);

								if (feeMaster != null && count != 0)
								{
									var profilePaymentInfo = new ProfilePaymentInfo
									{
										ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
										UserName = userName,
										AttendenceId = attendId,
										FeeType = ConstValues.FeeType.其他费用,
										FeeId = feeMaster.ID,
										Count = count,
										Fee = feeMaster.Price.Value * count,
										Discount = feeMaster.Price.Value * count,
										Currency = feeMaster.Currency,
										Creator = userName,
										CreateIP = ip,
										CreateDate = DateTime.Now
									};

									DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

									result.TotalFee += feeMaster.Price.Value * count;
									result.Discount += feeMaster.Price.Value * count;
									result.Currency = feeMaster.Currency;
								}
							}
						}
						break;
					case "invoicetitle":
						result.InvoiceTitle = str1.Trim();
						break;
					case "taxnum":
						result.TaxNum = str1.Trim();
						break;
					case "addressAndTel":
						result.AddressAndTel = str1.Trim();
						break;
					case "bank":
						result.Bank = str1.Trim();
						break;
					case "bankAccount":
						result.BankAccount = str1.Trim();
						break;
					case "invoiceDetail":
						result.InvoiceId = str1;
						break;
					case "favouriteTopic":
						result.FavouriteTopicId = str1.Trim();
						break;
					case "customize1":
						result.Customize1 = str1.Trim();
						break;
					case "customize2":
						result.Customize2 = str1.Trim();
						break;
					case "customize3":
						result.Customize3 = str1.Trim();
						break;
					case "customize4":
						result.Customize4 = str1.Trim();
						break;
					case "customize5":
						result.Customize5 = str1.Trim();
						break;
					case "concurrentEvent":
						var eventFee = await DbContext.ProfilePaymentInfo.Where(x => x.AttendenceId == attendId && x.FeeType == ConstValues.FeeType.同期活动费).ToListAsync();
						if (eventFee.Count > 0)
						{
							for (var i = 0; i < eventFee.Count; i++)
							{
								result.TotalFee -= eventFee[i].Fee;
								result.Discount -= eventFee[i].Fee;
							}

							DbContext.ProfilePaymentInfo.RemoveRange(eventFee);
						}
						if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
						{
							var concurrentEventList = str1.Split(ConstValues.chrComma);
							var concurrentEventCount = str2.Split(ConstValues.chrComma);
							for (var index = 0; index < concurrentEventList.Length; index++)
							{
								string tmp = concurrentEventList[index];
								int count = int.Parse(concurrentEventCount[index]);

								var feeMaster = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(x => x.ConcurrentEventId == tmp && x.Status == ConstValues.Status.正常
											&& (x.AttendenceIdentityId == str3 || x.AttendenceIdentityId == ConstValues.ApplicableForAll)
											&& x.Currency == str4);

								if (feeMaster != null && count != 0)
								{
									var profilePaymentInfo = new ProfilePaymentInfo
									{
										ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
										UserName = userName,
										AttendenceId = attendId,
										FeeType = ConstValues.FeeType.同期活动费,
										FeeId = feeMaster.ID,
										Count = count,
										Fee = feeMaster.Price.Value * count,
										Discount = feeMaster.Price.Value * count,
										Currency = feeMaster.Currency,
										Creator = userName,
										CreateIP = ip,
										CreateDate = DateTime.Now
									};

									DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

									result.TotalFee += feeMaster.Price.Value * count;
									result.Discount += feeMaster.Price.Value * count;
									result.Currency = feeMaster.Currency;
								}
							}
						}
						break;
					case "payType":
						result.PaymentTypeId = str1;
						break;
					default:
						break;

				}
				result.UpdateDate = DateTime.Now;
				result.UpdateIP = ip;
				result.Updater = userName;

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//主持人报告列表
		public async Task<JsonCamelCaseResult> GetChairmanReport(string name, string mail, string conferenceId)
		{
			var sql = from scheduleEventMst in DbContext.ScheduleEventMaster.AsNoTracking().Where(x => x.ConferenceId == conferenceId
					&& x.ChairmanMail == mail
					&& x.Chairman == name.Replace("~", " "))
				  join scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
					  on scheduleEventMst.ID equals scheduleInfo.ContributeId into t1
				  from schedule in t1.DefaultIfEmpty()
				  join topicMaster in DbContext.TopicMaster.AsNoTracking()
					  on scheduleEventMst.TopicId equals topicMaster.ID into t2
				  from topic in t2.DefaultIfEmpty()
				  join scheduleMaster in DbContext.ScheduleMaster.AsNoTracking()
					  on schedule.ScheduleId equals scheduleMaster.ID into t3
				  from scheduleMst in t3.DefaultIfEmpty()
				  where schedule.Status == ConstValues.ScheduleStatus.已安排
				  orderby schedule.ScheduleDate, schedule.StartTime
				  select new
				  {
					  Id = schedule.ID,
					  ScheduleDate = schedule.ScheduleDate.ToString(),
					  StartTime = schedule.StartTime.ToString().Substring(0, 5),
					  EndTime = schedule.EndTime.ToString().Substring(0, 5),
					  TopicId = topic.ID,
					  TopicName = topic.TopicName,
					  SchedulePlace = scheduleMst.SchedulePlace,
					  Chairman = scheduleEventMst.Chairman,
					  ChairmanMail = scheduleEventMst.ChairmanMail,
				  };

			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				Id = x.Id,
				ScheduleDate = !string.IsNullOrEmpty(x.ScheduleDate) ? x.ScheduleDate : string.Empty,
				StartTime = !string.IsNullOrEmpty(x.StartTime) ? x.StartTime : string.Empty,
				EndTime = !string.IsNullOrEmpty(x.EndTime) ? x.EndTime : string.Empty,
				TopicId = x.TopicId,
				TopicName = x.TopicName,
				SchedulePlace = x.SchedulePlace
			});
			return JsonCamelCase(new
			{
				data = result,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		public static string ChangeFavouriteTopicIdToName(string favouriteTopicId)
		{
			var DbContext = new CISEntities();
			if (string.IsNullOrEmpty(favouriteTopicId))
			{
				return string.Empty;
			}
			else
			{
				var topicMaster = DbContext.TopicMaster.AsNoTracking().Where(x => favouriteTopicId.Contains(x.ID.ToString())).Select(x => x.TopicName).ToList();
				return string.Join(ConstValues.strSemicolon, topicMaster);
			}
		}

		//获取学历 degreeMaster
		public async Task<JsonCamelCaseResult> GetDegree()
		{
			var sql = DbContext.DegreeMaster.AsNoTracking();

			if (sql != null)
			{
				var sqlResult = await sql.ToListAsync();

				var result = sqlResult.Select(x => new
				{
					Id = x.ID,
					DegreeName = x.DegreeName,
					DegreeNameEn = x.DegreeNameEn
				});

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//访问量
		public async Task<JsonResult> InsertLog(string ip, string actionName, string uid)
		{
			if (!string.IsNullOrEmpty(uid))
			{
				var data = await DbContext.SysUserMaster
						.FirstOrDefaultAsync(x => x.UserName == uid || x.Mail == uid);

				if (data == null)
				{
					return JsonCamelCase(new
					{
						data = "",
						code = "0",
						msg = "fail"
					},
					JsonRequestBehavior.AllowGet);
				}
			}

			var log = new LogInfo
			{
				ID = Utility.GetTableId(TableName.LogInfo),
				PageLogsType = PageLogsType.用户,
				Action = actionName,
				ConferenceId = string.Empty,
				NewsListId = string.Empty,
				NewsId = string.Empty,
				View = string.Empty,
				Controller = 客户端.Mobile,
				Path = SystemWeb + "/Mobile/" + actionName,
				Client = 客户端.Mobile,
				Status = Status.正常,
				Sort = 6666,
				Remark = string.Empty,
				Creator = string.IsNullOrEmpty(uid) ? string.Empty : uid,
				CreateIP = ip,
				CreateDate = DateTime.Now,
				Updater = string.Empty,
				UpdateIP = string.Empty,
				UpdateDate = DateTime.Now
			};

			var dbContext = new CISEntities();

			DbContext.LogInfo.Add(log);
			await DbContext.SaveChangesAsync();
			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//手机支付
		//获取PayTypeID
		public async Task<JsonCamelCaseResult> GetAliPayType(string conferenceId)
		{
			var sysPayMaster = await DbContext.SysPaymentMaster.FirstOrDefaultAsync(x => x.PaymentName == ConstValues.PayType.支付宝);

			var conferencePayMaster = await DbContext.ConferencePaymentMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.PayId == sysPayMaster.ID);

			if (conferencePayMaster != null)
			{
				var result = new
				{
					PayType = string.IsNullOrEmpty(conferencePayMaster.ID) ? string.Empty : conferencePayMaster.ID
				};
				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//获取支付宝配置参数
		public async Task<JsonCamelCaseResult> GetAlipaySetting(string conferenceId)
		{
			var data = await DbContext.AlipayMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ConferenceId == conferenceId);

			if (data != null)
			{
				var result = new
				{
					Partner = string.IsNullOrEmpty(data.Partner) ? string.Empty : data.Partner,
					AccountName = string.IsNullOrEmpty(data.AccountName) ? string.Empty : data.AccountName,
					SellerMail = string.IsNullOrEmpty(data.SellerMail) ? string.Empty : data.SellerMail,
					AppId = string.IsNullOrEmpty(data.AppId) ? string.Empty : data.AppId,
					Rsa = string.IsNullOrEmpty(data.Rsa) ? string.Empty : data.Rsa
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//创建PayRecord
		public async Task<JsonResult> CreatePayRecord(string username, string fee, string attendenceId, string currency)
		{
			var newID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentRecord);
			var paymentRecord = new ProfilePaymentRecord
			{
				ID = newID,
				UserName = username,
				AttendenceId = attendenceId,
				Fee = Utility.ObjectToDouble(fee),
				Currency = currency,
				FeeStatus = false,
				Creator = username,
				CreateDate = DateTime.Now
			};

			var dbContext = new CISEntities();

			DbContext.ProfilePaymentRecord.Add(paymentRecord);
			await DbContext.SaveChangesAsync();
			return JsonCamelCase(new
			{
				data = paymentRecord,
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//支付成功
		public async Task<JsonResult> PaySuccessMobile(string conferenceId, string recordId, string attendenceId, string actuallyFeeStr)
		{
			//获取PayTypeID
			var sysPayment = await DbContext.SysPaymentMaster.FirstOrDefaultAsync(x => x.PaymentName == ConstValues.PayType.支付宝);

			var conferencePayment = await DbContext.ConferencePaymentMaster.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId && x.PayId == sysPayment.ID);

			string payType = string.IsNullOrEmpty(conferencePayment.ID) ? string.Empty : conferencePayment.ID;

			//支付成功
			double? actuallyFee = Utility.ObjectToDouble(actuallyFeeStr);

			var paymentRecord = await DbContext.ProfilePaymentRecord.FirstOrDefaultAsync(x => x.ID == recordId);

			if (paymentRecord != null)
			{
				paymentRecord.FeeStatus = true;
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == paymentRecord.AttendenceId);
			if (result != null)
			{
				result.HasPaid = true;
				result.PaymentTypeId = payType;
				result.ActuallyFee = actuallyFee;
				result.UpdateDate = DateTime.Now;
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}

			#region SendMail
			var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.MailType == ConstValues.MailType.注册服务邮箱 &&
						x.ConferenceId == conferenceId);

			if (conferenceMailServerMaster == null)
			{
				conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.MailType == ConstValues.MailType.会议邮箱 &&
							x.ConferenceId == conferenceId);
			}

			if (conferenceMailServerMaster != null)
			{
				var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == conferenceId);

				MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
				MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
				MailAddress to = new MailAddress(result.Mail);

				MailMessage message = Utility.GetMailContent(new MailModel
				{
					MailRemark = ConstValues.MailSubject.缴费成功,
					Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn,
					UserName = result.FullName,
					ConferenceId = conferenceMaster.ID,
					ConferenceName = conferenceMaster.ConferenceName,
					ConferenceNickName = conferenceMaster.ConferenceNickName,
					ConferenceUrl = !string.IsNullOrEmpty(conferenceMaster.HomePageUrl) ? conferenceMaster.HomePageUrl :
						ConstValues.SystemWeb + "/MeetingMain/Index/" + conferenceMaster.ConferenceNickName,
					Currency = paymentRecord.Currency,
					TotalFee = actuallyFee.Value.ToString("N2"),
					PaymentType = conferenceMaster.IsInternational ? sysPayment.PaymentNameEn : sysPayment.PaymentName,
					PaidStatus = Resources.HasPaid
				});
				message.To.Add(to);

				if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
				{
					foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
					{
						if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
						{
							message.Bcc.Add(new MailAddress(cc.Trim()));
						}
					}
				}

				var strMsg = string.Empty;
				var mailTask = Task.Run(() =>
				{
					strMsg = sender.SendMail(from, message, conferenceMailServerMaster.Password);
				});
				if (string.IsNullOrEmpty(strMsg))
				{
					result.HasSendPaid = true;
				}
			}
			#endregion

			await DbContext.SaveChangesAsync();
			return JsonCamelCase(new
			{
				data = "",
				code = "1",
				msg = "success"
			},
			JsonRequestBehavior.AllowGet);
		}

		//获取历史版本号
		public async Task<JsonCamelCaseResult> GetHistoryVersion(string mobileType)
		{
			var data = await DbContext.VersionInfo.AsNoTracking().FirstOrDefaultAsync(x => x.MobileType == mobileType && x.Status == true);

			if (data != null)
			{
				var result = new
				{
					MobileType = data.MobileType,
					VersionNo = data.VersionNo
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}

		//是否已经支付
		public async Task<JsonCamelCaseResult> GetHasPaidOrNot(string attendenceId)
		{
			var data = await DbContext.ConferenceAttendenceInfo.AsNoTracking().FirstOrDefaultAsync(x => x.ID == attendenceId);

			if (data != null)
			{
				var result = new
				{
					HasPaid = data.HasPaid
				};

				return JsonCamelCase(new
				{
					data = result,
					code = "1",
					msg = "success"
				},
				JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(new
				{
					data = "",
					code = "0",
					msg = "fail"
				},
				JsonRequestBehavior.AllowGet);
			}
		}
	}
}